简体   繁体   English

“没有名为‘django_heroku’的模块”应用程序无法在 Heroku 上启动

[英]"No module named 'django_heroku' " app won't start on Heroku

Trying to push to the heroku server, I get this:尝试推送到 heroku 服务器,我得到了这个:

git push heroku master

remote: Building source:
remote:
remote: -----> Python app detected
remote:  !     Python has released a security update! Please consider upgrading to python-3.7.3
remote:        Learn More: https://devcenter.heroku.com/articles/python-runtimes
remote: -----> Installing requirements with pip
remote:
remote: -----> Downloading NLTK corpora…
remote:  !     'nltk.txt' not found, not downloading any corpora
remote:  !     Learn more: https://devcenter.heroku.com/articles/python-nltk
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 206.4M
remote: -----> Launching...
remote:        Released v10
remote:        https://versally.herokuapp.com/ deployed to Heroku

However, when I go to my app, it tells me there's an error.但是,当我转到我的应用程序时,它告诉我有一个错误。 When I check in on the logs, I see this:当我检查日志时,我看到:

2019-04-30T13:22:00.633794+00:00 app[web.1]: import django_heroku
2019-04-30T13:22:00.633801+00:00 app[web.1]: ModuleNotFoundError: No module named 'django_heroku'
2019-04-30T13:22:00.634020+00:00 app[web.1]: [2019-04-30 13:22:00 +0000] [11] [INFO] Worker exiting (pid: 11)
2019-04-30T13:22:00.789044+00:00 app[web.1]: [2019-04-30 13:22:00 +0000] [4] [INFO] Shutting down: Master

I'm yet to setup the database, but I'm just looking to get a debug message from the django code so I can start with configuration of the database.我还没有设置数据库,但我只是想从 django 代码中获取调试消息,这样我就可以开始配置数据库了。

I ran into this issue myself and discovered the problem.我自己遇到了这个问题并发现了这个问题。 This error will happen if the module cannot be found, as the name of the error explains.如果找不到模块,就会发生此错误,正如错误名称所解释的那样。 If the virtual environment containing the module is not included in the code pushed to heroku, then the module cannot be found.如果推送到 heroku 的代码中不包含包含该模块的虚拟环境,则无法找到该模块。

If you are using pipenv as your virtual environment, you will get this error.如果你使用 pipenv 作为你的虚拟环境,你会得到这个错误。 To fix this, you will need to do the following:要解决此问题,您需要执行以下操作:

  1. Delete the Pipfile and Pipfile.lock files.删除 Pipfile 和 Pipfile.lock 文件。

  2. Outside the pipenv,issue the following commands:在 pipenv 之外,发出以下命令:

python -m venv virtual_environment_name

virtual_environment_name/Scripts/Activate (Windows) virtual_environment_name/Scripts/Activate (Windows)

source virtual_environment_name/bin/activate (Mac) source virtual_environment_name/bin/activate (Mac)

  1. Install the packages previously installed again.再次安装之前安装的软件包。

  2. Run the git add .运行git add . and git commit -am "Some text here" commands.git commit -am "Some text here"命令。

You should be good to go!你应该很高兴去!

For anyone out there with this problem, I solved it by emptying my requirements.txt, pushing (which forces Heroku to uninstall all the requirements) then pushing populated requirements through aggain. 对于存在此问题的任何人,我都可以通过清空我的requirements.txt,推送(这将迫使Heroku卸载所有需求)然后通过重新推送填充的需求来解决。

I had to make sure gunicorn was included in requirements - which it was, but a log showed that for some reason heroku uninstalled my 'stale' version. 我必须确保需求中包括了gunicorn-确实如此,但是日志显示出于某种原因heroku卸载了我的“陈旧”版本。

Heroku + gunicorn not working (bash: gunicorn: command not found ) Heroku + Gunicorn不起作用(bash:gunicorn:找不到命令)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM