2016-01-05 50 views
2

我試圖讓一個Django應用程序啓動並運行。這些庫有點過時(它目前在Django 1.4上)。ImportError:無法導入名稱SortedDict - 只在Python 2.7上,而不是2.6

我有或多或少的工作時,我試圖蟒蛇2.6,但是當我使用Python 2.7更改爲virtualenv中我得到的錯誤:

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 

我成立了virtualenvs具有相同要求的文件。

可能導致此問題的版本之間有什麼區別?

回答

5

SortedDictremoved in Django 1.9。確保你已經在舊虛擬環境中安裝了相同版本的Django。

如果是您自己的代碼使用SortedDict,則長期修復將更新代碼以使用在Python 2.7中添加的collections.OrderedDict。就你而言,看起來導入錯誤來自第三方應用程序,爲了使代碼能夠在Django 1.9上運行,你必須更新或替換它。

+0

謝謝,現在我檢查了一下,我確實設法在該virtualenv中安裝了1.9版。根據需求文件,我認爲我有1.4.5。 –

相關問題