0

我一直在做一个 Django 项目,这是我的第一个项目,没有任何问题。我关闭了文件并重新启动计算机以进行软件更新,现在我收到以下错误:

Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    execute_manager(settings)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 436, in execute_manager
setup_environ(settings_mod)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 419, in setup_environ
    project_module = import_module(project_name)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
ImportError: No module named Stentorian

模块名称是项目的名称。我无法弄清楚导致此错误的可能原因。任何洞察力将不胜感激。

编辑:这是 Python sys.path:

['', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/distribute-0.6.24-    py2.7.egg', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info', '/Library/Python/2.7/site-packages']
4

1 回答 1

0

确保这个Stentorian项目目录有一个__init__.py. 您可以在 Mac 上将父目录添加到PYTHONPATH环境变量中~/.bash_profile,也可以在manage.py脚本中附加目录。在您的 bash_profile 中,在 PYTHONPATH 上拥有 和 是非常习惯的...

 PYTHONPATH=.:..:/path/to/parent:${PYTHONPATH}

或者,在 manage.py 脚本中:

import sys
sys.path.insert(0, '.')
sys.path.insert(0, '..')
于 2012-05-27T06:00:44.313 回答