简体   繁体   English

出现错误 => ModuleNotFoundError: No module named 'django' 当我尝试将 django 应用程序部署到 heroku 时

[英]Getting Error => ModuleNotFoundError: No module named 'django' When I attempt to deploy my django app to heroku

When I attempt to deploy my django app to heroku, the deployment will fail with the following error message当我尝试将我的 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?

Here is my requirements.txt这是我的要求.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

My Procfile我的档案

release: python3 manage.py migrate
web: gunicorn app_name.wsgi --log-file -

And the buildpacks (using nodejs for the frontend)和 buildpacks(使用 nodejs 作为前端)

1. heroku/nodejs
2. heroku/python

I have tried to deploy the app from both the CLI and a github repository.我尝试从 CLI 和 github 存储库部署应用程序。 Both result in the same error.两者都会导致相同的错误。

I am happy to provide any additional information from the project if needed.如果需要,我很乐意提供该项目的任何其他信息。

How can I fix this error so my app will deploy successfully?如何修复此错误,以便我的应用程序能够成功部署?

UPDATE更新

I edited my Procfile to the following我将我的 Procfile 编辑为以下

web: gunicorn app_name.wsgi --log-file -

When I attempt to deploy using this Procfile, I am getting the following error in my heroku logs当我尝试使用此 Procfile 进行部署时,我的 heroku 日志中出现以下错误

app[web.1]: bash: gunicorn: command not found

So it seems like Heroku is not able to use any of the packages I listed in the requirements.txt.因此,Heroku 似乎无法使用我在 requirements.txt 中列出的任何包。 Any guesses as to why this may be happening?关于为什么会发生这种情况的任何猜测?

SOLVED!解决了!

I had both a Pipfile and a requirements.txt in my project.我的项目中有一个 Pipfile 和一个 requirements.txt。 Heroku seems to default to reading the Pipfile to find dependencies. Heroku 似乎默认读取 Pipfile 以查找依赖项。 I was only using requirements.txt to list my dependencies, and my Pipfile did not list any.我只使用 requirements.txt 列出我的依赖项,而我的 Pipfile 没有列出任何依赖项。

Solution: Deleted Pipfile and everything worked perfectly!解决方案:删除 Pipfile,一切正常!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ModuleNotFoundError:当我尝试在 heroku 上部署我的 django 项目时,没有名为“fcntl”的模块 - ModuleNotFoundError: No module named 'fcntl' when I try to deploy my django project on heroku ModuleNotFoundError:将我的 Django 应用程序迁移到 Heroku 时,没有名为“Django-Banking-App.settings”的模块 - ModuleNotFoundError: No module named 'Django-Banking-App.settings' when migrating my Django app to Heroku 当我运行应用程序时,我收到此错误 ModuleNotFoundError: No module named 'preferences' in django - when i run the app i am getting this error ModuleNotFoundError: No module named 'preferences' in django Heroku Django ModuleNotFoundError:没有名为“my_app”的模块 - Heroku Django ModuleNotFoundError: No module named 'my_app' heroku 上的 Django 应用程序,ModuleNotFoundError:没有名为“spread”的模块 - Django app on heroku, ModuleNotFoundError: No module named 'spread' ModuleNotFoundError:当我使用 heroku 迁移文件时,没有名为“django_apscheduler”的模块 - ModuleNotFoundError: No module named 'django_apscheduler' when I migrate my file with heroku ModuleNotFoundError:Heroku中没有名为“ django”的模块 - ModuleNotFoundError: No module named 'django' in Heroku 尝试在 Azure 上部署 Django 服务器时出现“ModuleNotFoundError: No module named 'django'” - "ModuleNotFoundError: No module named 'django'" when trying to deploy Django server on Azure Django / Heroku 部署 - ModuleNotFoundError:“没有名为 'django' 的模块” - Django / Heroku Deploying - ModuleNotFoundError: "No module named 'django'" 将 Django 部署到 Heroku 时:ModuleNotFoundError: No module named 'env' - When deploying Django to Heroku: ModuleNotFoundError: No module named 'env'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM