在 conda 环境中在 Ubuntu 上运行 gunicorn

jgu*_*man 2 python ubuntu gunicorn conda

我正在尝试在运行 Ubuntu 的 EC2 实例上部署 Flask 应用程序。我已经设置了我的 WSGI 文件,但是我在运行 gunicorn 时遇到了一些问题。起初,我安装了 gunicorn sudo apt-get install gunicorn。但是,它使用错误版本的 python 运行,并且为我的 Flask 应用程序使用的每个模块抛出了导入错误。我确定这是因为我使用 conda 作为环境管理器,并且因为apt-get在权限虚拟环境之外使用放置的 gunicorn 进行安装。因此,我卸载了 gunicorn ( sudo apt-get purge gunicorn) 并通过conda ( ) 重新安装了它conda install gunicorn。现在,当我运行 gunicorn ( gunicorn --bind 0.0.0.0:8000 wsgi:app) 时,我没有得到 50 行的回溯。但是,我确实收到以下错误:-bash: /usr/bin/gunicorn: No such file or directory. 我尝试卸载 gunicorn 并使用 pip 重新安装,但我仍然遇到相同的错误。我试过在 Google 和 StackOverflow 上搜索解决方案,但我发现我应该在虚拟环境中安装 gunicorn 来克服这个错误(我相信,我已经这样做了)。我猜有一个简单的解决方法,这个问题与我的无能有关,而不是 conda 或其他东西。任何建议将不胜感激。谢谢。

jgu*_*man 5

所以,我是对的 - 问题完全与我自己的无能有关。不过,我不会删除这个问题,而是自己回答并留在这里,以防将来任何初出茅庐的开发人员遇到同样的问题。事实证明,问题是我gunicorn --bind 0.0.0.0:8000 wsgi:app在错误的目录中运行。在我cd进入包含 的目录后wsgi.py,gunicorn 工作得很好。要点:gunicorn 必须从包含wsgi.py.