当前位置:  开发笔记 > 编程语言 > 正文

ImportError:无法导入名称SortedDict - 仅在Python 2.7上,而不是2.6

如何解决《ImportError:无法导入名称SortedDict-仅在Python2.7上,而不是2.6》经验,为你挑选了1个好方法。

我正在尝试启动并运行Django应用程序.这些库有点过时(目前在Django 1.4上).

当我尝试使用python 2.6时,我或多或少地工作了,但是当我使用python 2.7更改为virtualenv时,我得到错误:

Unhandled exception in thread started by 
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 
from django.utils.datastructures import SortedDict
ImportError: cannot import name SortedDict

我用相同的需求文件设置了virtualenvs.

可能导致此问题的版本之间有什么区别?



1> Alasdair..:

SortedDict在Django 1.9中删除了.确保在新虚拟环境中安装了与旧版本相同的Django版本.

如果它是您自己使用的代码SortedDict,那么长期修复就是更新要使用的代码collections.OrderedDict,这是在Python 2.7中添加的.在您的情况下,看起来导入错误来自第三方应用程序,您必须更新或替换它以使代码与Django 1.9一起使用.

推荐阅读
爱唱歌的郭少文_
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有