【问题标题】:Heroku + gunicorn not working (bash: gunicorn: command not found )Heroku + gunicorn 不工作(bash: gunicorn: command not found )
【发布时间】:2016-01-06 10:26:05
【问题描述】:

我成功安装了 gunicorn:

remote: -----> Removing .DS_Store files
remote: -----> Python app detected
remote: -----> Installing dependencies with pip
remote:        Collecting gunicorn==19.0.0 (from -r requirements.txt (line 1))
remote:          Downloading gunicorn-19.0.0.tar.gz (382kB)
remote:        Installing collected packages: gunicorn
remote:          Running setup.py install for gunicorn
remote:        Successfully installed gunicorn-19.0.0

我的档案:

web: gunicorn myapp:app --log-file=-

但应用在部署时崩溃:

bash: gunicorn: command not found 

我尝试添加 heroku python buildpack,但没有成功。如果我回滚到之前的提交(requirements.txtProcile 都没有改变),它可以工作:

heroku/web.1:  Starting process with command `gunicorn myapp:app --log-file=-` 
app/web.1:  2015-10-08 17:04:18 [3] [INFO] Listening at: http://0.0.0.0:51854 (3)

【问题讨论】:

    标签: heroku gunicorn


    【解决方案1】:

    确保gunicorn 在您的requirements.txt

    【讨论】:

    • 它就在那里,请注意我的问题中的remote: Collecting gunicorn==19.0.0 (from -r requirements.txt (line 1))。不过还是谢谢。
    • 尝试在 heroku 中重新创建您的应用程序。
    • 我重新创建了它,同样的问题。
    【解决方案2】:

    远程卸载所有需求并重新安装后,问题似乎自行解决。

    【讨论】:

    • 部署一个空的需求文件,然后部署原来的。
    • 一个空的需求文件给我:“你必须给出至少一个安装需求(参见“pip help install”)”
    • Patrice 好的警告,我也遇到了这个问题,所以我将从我的需求文件中删除除第一个之外的所有内容。
    • 这是一个神秘的解决方案!
    • @maxko87 清空需求是对的,它构建了应用程序,但是在我推送完整需求时它再次崩溃
    【解决方案3】:

    我错过了 heroku/python buildpack 所以我去了仪表板并:

    Settings -> Add buildpack -> heroku/python
    

    【讨论】:

      【解决方案4】:

      如果您在项目根目录中同时拥有 requirements.txt 和 Pipfile,那么我建议您删除 Pipfile 并将所有需求列在 requirements.txt 文件中(包括 gunicorn)。

      然后它会显示:“Installing requirements from pip”,并且将安装 requirements.txt 中列出的所有需求。

      【讨论】:

        【解决方案5】:

        检查gunicorn 是否在requirements.txt 中后运行:

        pip install -r requirements.txt
        

        我的输出包含多个Requirement already satisfied: ...,但未安装gunicorn

        Collecting gunicorn (from -r requirements.txt (line 2))
        Using cached ...
        
        Installing collected packages: gunicorn
        Successfully installed gunicorn-19.9.0
        

        【讨论】:

          【解决方案6】:

          就我而言,我在“Procfile”中遇到了问题。
          我在 gunicorn 之后删除了 :

          web: gunicorn: app:app -> web: gunicorn app:app

          【讨论】:

            【解决方案7】:

            Heroku 的 Python 文档似乎已经过时了...显然他们现在更喜欢 Pipfile 而不是 requirements.txt,但幸运的是,您可以使用 pipenv 轻松生成一个。

            试试这个:

            $ pip3 install --user pipenv 安装 pipenv

            $ pipenv install gunicorn 将 gunicorn 添加到 pipfile 中

            $ pipenv shell激活

            我遇到了完全相同的错误,这对我有用!

            【讨论】:

              【解决方案8】:

              在我的情况下,由于我在同一目录/项目中同时拥有 PipfilePipfile.lockrequirements.txt 文件,因此发生了冲突。

              Heroku 没有从 requirements.txt 安装任何东西,因此与这里的每个人都出现了相同的 gunicorn 错误。

              【讨论】:

                【解决方案9】:

                您还需要确保在运行git push heroku master 时,要求是从 requirements.txt 而不是从 pipfile 或 pipfile.lock 安装的。因此,如果您使用 requirements.txt 安装依赖项,请确保从 cd 目录中删除这些文件

                【讨论】:

                  【解决方案10】:

                  在您的虚拟环境中安装gunicorn

                  pip install gunicorn
                  

                  然后更新您的requirements.txt 文件

                  pip freeze > requirements.txt
                  

                  【讨论】:

                    【解决方案11】:

                    在 requirements.txt 中添加 gunicorn 解决了我的问题。

                    【讨论】:

                      【解决方案12】:

                      在我的情况下,即使 gunicorn 在 requirements.txt 中,gunicorn 也没有安装,因为存在 Pipfile。我从我的 github 存储库中删除了 Pipfile 并成功重新部署。

                      以下简短教程也有助于确保我正确配置了 runtime.txt、wsgi.py 和 Procfile 的基本要素。

                      https://www.geeksforgeeks.org/deploy-python-flask-app-on-heroku/

                      【讨论】:

                        【解决方案13】:

                        在我的情况下,这是因为 Pipfile gunicorndev-packages 之下。将其安装为常规软件包即可。只有Pipfile。不需要requirements.txt

                        【讨论】:

                          【解决方案14】:

                          我遇到了同样的问题,但添加后 gunicorn===<latest-version> 到 requirements.txt 文件已修复。

                          【讨论】:

                            【解决方案15】:

                            我不知道它为什么起作用,但我遇到了同样的问题,在阅读了其他建议后,我最终删除了我的 requirements.txt 文件(即使它有 gunicorn)并再次运行 pip freeze > requirements.txt 并且它解决了问题。

                            【讨论】:

                              【解决方案16】:

                              就我而言,我的 Heroku 应用缺少 python buildpack,因此没有安装任何包

                              我通过添加一个来解决这个问题:Settings > Buildpacks > Add buildpack > python

                              【讨论】:

                                【解决方案17】:

                                当 gunicorn 未正确安装时会发生这种情况... 并且为了再次安装,如果requirments.txt有变化,安装程序只能安装一个文件

                                所以请按照以下步骤操作:-

                                首先,在requirments.txt中安装一个Empty或者只有一个东西 将让安装程序安装一些东西,因为 requirments.txt 有变化,并在 git inti .... 之后遵循完整的设置,依此类推

                                之后,使用完整的 requirments.txt 文件重复所有步骤 它肯定会工作....

                                我的就是这样解决的.. 谢谢

                                【讨论】:

                                  猜你喜欢
                                  • 2019-07-07
                                  • 2014-08-23
                                  • 2014-07-01
                                  • 2018-07-18
                                  • 2010-12-09
                                  • 1970-01-01
                                  • 1970-01-01
                                  • 1970-01-01
                                  • 2018-06-06
                                  相关资源
                                  最近更新 更多