我有一个叫做django_trial_on_mac
的Django应用程序,我最近搬到了GitHub,以便将来将它部署到heroku。我将项目克隆到mac上的本地GitHub文件夹,但当我从新目录运行应用程序时,我收到以下错误:
Traceback (most recent call last):
File "/Users/danieloram/GitHub/Python_projects_for_github/django_trial_on_mac/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/django/core/management/__init__.py", line 303, in execute
settings.INSTALLED_APPS
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/django/conf/__init__.py", line 92, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/importlib/__init__.py", line 124, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/importlib/_bootstrap.py", line 807, in _gcd_import
_gcd_import(parent)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/importlib/_bootstrap.py", line 824, in _gcd_import
raise ImportError(_ERR_MSG.format(name))
ImportError: No module named django_trial_on_mac
我还没有找到这个错误的具体情况的解决方案,我希望有人能解释或指向我对某个地方,我可以找到答案。谢谢!
问题原来是我有一个非标准的项目目录结构。我在我的'django_trial_on_mac'目录中缺少__init__.py
文件。一旦我在那里创建了一个空的__init__.py
文件,应用程序就正常运行了。
__init__.py
文件告诉Django这个目录应该被当作一个包来对待,因为这个文件不存在于'django_trial_on_mac'目录中,所以它不能导入'django_trial_on_mac'模块。
没有更多信息很难回答,但看起来PYTHONPATH
env变量在你的Heroku上有问题:
- 不包含项目目录,或者
- 可能有一个非标准的项目目录结构,或者 问题可能是一些简单的东西,如上传项目与它的父目录,而不仅仅是项目目录…