I am trying to get a Django application up and running. The libraries are a bit out of date (its currently on Django 1.4).
I have got it more or less working when I tried python 2.6, but when I change to a virtualenv using python 2.7 I get the error:
Unhandled exception in thread started by <function wrapper at 0x7f057b17c320>
Traceback (most recent call last):
File "/home/colin/software/virtualenvs/barshool/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/home/colin/software/virtualenvs/barshool/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/home/colin/software/virtualenvs/barshool/lib/python2.7/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/home/colin/software/virtualenvs/barshool/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/home/colin/software/virtualenvs/barshool/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/colin/software/virtualenvs/barshool/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/home/colin/software/virtualenvs/barshool/lib/python2.7/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/colin/software/virtualenvs/barshool/lib/python2.7/site-packages/transmeta/__init__.py", line 7, in <module>
from django.utils.datastructures import SortedDict
ImportError: cannot import name SortedDict
I set up the virtualenvs with the same requirements files.
What is the difference between the versions that could be causing this?
SortedDict
was removed in Django 1.9. Make sure you have installed the same version of Django in the new virtual environment as the old one.
If it was your own code that was using SortedDict
, the long term fix would be to update the code to use collections.OrderedDict
, which was added in Python 2.7. In your case, it looks like the import error is coming from a third party app, which you'll have to update or replace to make the code work with Django 1.9.
This seems a persistent bug. Meant the same issue while working with django==1.11.1
and djangorestframework==3.9.1
. It was particularly djangorestframework (drf) which was importing the sortedDict
, so i instead updated drf. The latest version at this time is djangorestframework==3.10.3
from the python foundation. This drf upgrade solved my challenge.
Note: I was working with python 3.6.8
, on Ubuntu 18.04.3 LTS
(just in case you need those specifics)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With