Getting Error => ModuleNotFoundError: No module named 'django' When I attempt to deploy my django app to heroku
Getting Error => ModuleNotFoundError: No module named 'django' When I attempt to deploy my django app to heroku
当我尝试将我的 django 应用程序部署到 heroku 时,部署将失败并显示以下错误消息
Traceback (most recent call last):
File "manage.py", line 11, in main
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 23, in <module>
main()
File "manage.py", line 13, in main
raise ImportError(
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
这是我的requirements.txt
asgiref==3.3.4
dj-database-url==0.5.0
Django==3.2.3
django-cors-headers==3.7.0
django-on-heroku==1.1.2
djangorestframework==3.12.4
gunicorn==20.1.0
psycopg2-binary==2.8.6
python-dotenv==0.17.1
pytz==2021.1
sqlparse==0.4.1
whitenoise==5.2.0
我的程序文件
release: python3 manage.py migrate
web: gunicorn app_name.wsgi --log-file -
和构建包(前端使用 nodejs)
1. heroku/nodejs
2. heroku/python
我尝试从 CLI 和 github 存储库部署应用程序。两者都会导致相同的错误。
如果需要,我很乐意提供该项目的任何其他信息。
如何修复此错误以便我的应用程序能够成功部署?
更新
我将 Procfile 编辑为以下内容
web: gunicorn app_name.wsgi --log-file -
当我尝试使用此 Procfile 进行部署时,我的 heroku 日志中出现以下错误
app[web.1]: bash: gunicorn: command not found
所以 Heroku 似乎无法使用我在 requirements.txt 中列出的任何软件包。关于为什么会发生这种情况的任何猜测?
已解决!
我的项目中有一个 Pipfile 和一个 requirements.txt。 Heroku 似乎默认读取 Pipfile 来查找依赖项。我只是使用 requirements.txt 来列出我的依赖项,而我的 Pipfile 没有列出任何依赖项。
解决方案:删除 Pipfile,一切正常!
当我尝试将我的 django 应用程序部署到 heroku 时,部署将失败并显示以下错误消息
Traceback (most recent call last):
File "manage.py", line 11, in main
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 23, in <module>
main()
File "manage.py", line 13, in main
raise ImportError(
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
这是我的requirements.txt
asgiref==3.3.4
dj-database-url==0.5.0
Django==3.2.3
django-cors-headers==3.7.0
django-on-heroku==1.1.2
djangorestframework==3.12.4
gunicorn==20.1.0
psycopg2-binary==2.8.6
python-dotenv==0.17.1
pytz==2021.1
sqlparse==0.4.1
whitenoise==5.2.0
我的程序文件
release: python3 manage.py migrate
web: gunicorn app_name.wsgi --log-file -
和构建包(前端使用 nodejs)
1. heroku/nodejs
2. heroku/python
我尝试从 CLI 和 github 存储库部署应用程序。两者都会导致相同的错误。
如果需要,我很乐意提供该项目的任何其他信息。
如何修复此错误以便我的应用程序能够成功部署?
更新
我将 Procfile 编辑为以下内容
web: gunicorn app_name.wsgi --log-file -
当我尝试使用此 Procfile 进行部署时,我的 heroku 日志中出现以下错误
app[web.1]: bash: gunicorn: command not found
所以 Heroku 似乎无法使用我在 requirements.txt 中列出的任何软件包。关于为什么会发生这种情况的任何猜测?
已解决!
我的项目中有一个 Pipfile 和一个 requirements.txt。 Heroku 似乎默认读取 Pipfile 来查找依赖项。我只是使用 requirements.txt 来列出我的依赖项,而我的 Pipfile 没有列出任何依赖项。
解决方案:删除 Pipfile,一切正常!