我在普通的Python外殼和我正在試圖導入我的項目模型,當這個錯誤:from django.db import utils ImportError無法導入名稱utils?
from results.models import TestResult
Traceback (most recent call last):
File "C:\Program Files (x86)\Wing IDE 3.2\src\debug\tserver\_sandbox.py", line 1, in <module>
# Used internally for debug sandbox under external interpreter
File "C:\Users\audrey_moreau\myProject\results\models.py", line 1, in <module>
from django.db import models
File "c:\Python27\Lib\site-packages\django\db\__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "c:\Python27\Lib\site-packages\django\db\__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "c:\Python27\Lib\site-packages\django\db\utils.py", line 92, in __getitem__
backend = load_backend(db['ENGINE'])
File "c:\Python27\Lib\site-packages\django\db\utils.py", line 54, in load_backend
return import_module('.base', backend_name)
File "c:\Python27\Lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "c:\Python27\Lib\site-packages\django\db\backends\sqlite3\base.py", line 14, in <module>
from django.db import utils
ImportError: cannot import name utils
誰能給我就如何解決這一問題的指針?我正在使用Python 2.7。
重新安裝Django –
您是否創建了自己的名爲'utils'的包或模塊,這可能會導致奇怪的衝突?不確定重新安裝Django是其答案,因爲它清楚地找到了django.db.utils文件。堆棧跟蹤顯示其執行代碼。 – mleonard87
您是否正確設置了環境?你說你在普通的python shell中,但要使用django模型,你需要在django shell中或者配置你的shell工作。 – aherok