发布于2021-07-24 21:21 阅读(1018) 评论(0) 点赞(26) 收藏(5)
最近,我将Django框架的版本从2.0.6
to升级3.0
,突然在调用python manage.py shell
命令后,我得到了这个异常:
导入错误:无法从“django.utils”导入名称“6”(/path-to-project/project/venv/lib/python3.7/site-packages/django/utils/ init .py)
完整跟踪:
Traceback (most recent call last):
File "manage.py", line 13, in <module>
execute_from_command_line(sys.argv)
File "/path-to-project/project/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/path-to-project/project/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 377, in execute
django.setup()
File "/path-to-project/project/venv/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/path-to-project/project/venv/lib/python3.7/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/path-to-project/project/venv/lib/python3.7/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/path-to-project/project/venv/lib/python3.7/site-packages/corsheaders/__init__.py", line 1, in <module>
from .checks import check_settings # noqa: F401
File "/path-to-project/project/venv/lib/python3.7/site-packages/corsheaders/checks.py", line 7, in <module>
from django.utils import six
类似问题:
我读了这个问题和这个django-3.0,发行说明,但这些资源帮不了我。
在Django的3.0.0版本说明指定某些私人的Python 2兼容的API被拆除。其中有django.utils.six
.
对于此错误,@WillemVanOnsem 指出该模块corsheaders
正在引用此模块。
对于遇到同样问题的其他人,查看堆栈跟踪最后一行的文件路径可以帮助识别有问题的模块。我见过的另一个例子是:
...
File "/path/to/project/venv/lib/python3.8/site-packages/parler/utils/conf.py", line 10, in <module>
from django.utils import six
ImportError: cannot import name 'six' from 'django.utils' (/path/to/project/venv/lib/python3.8/site-packages/django/utils/__init__.py)
在这种情况下,导致问题的模块是parler
. 我希望这可以帮助遇到此问题的任何其他人。
作者:官方问答小能手
链接:http://www.pythonpdf.com/blog/article/246/ba3d2bdf7c6edde2568f/
来源:编程知识网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!