简体   繁体   English

在conda环境中在Ubuntu上运行gunicorn

[英]Running gunicorn on Ubuntu in a conda environment

I'm trying to deploy a Flask app on an EC2 instance running Ubuntu. 我正在尝试在运行Ubuntu的EC2实例上部署Flask应用程序。 I have my WSGI file set up, but I'm having some issues running gunicorn. 我已经设置了WSGI文件,但是在运行gunicorn时遇到了一些问题。 At first, I installed gunicorn with sudo apt-get install gunicorn . 首先,我使用sudo apt-get install gunicorn However, it ran with the wrong version of python, and it threw import errors for each of the modules my Flask app uses. 但是,它运行了错误版本的python,并为Flask应用程序使用的每个模块引发了导入错误。 I ascertained that this was due to the fact that I use conda as an environment manager, and because installing with apt-get placed gunicorn outside of the purview virtual environment. 我确定这是由于我使用conda作为环境管理器,并且因为使用apt-get放置的gunicorn进行安装是在权限虚拟环境之外。 So, I uninstalled gunicorn ( sudo apt-get purge gunicorn ) and reinstalled it through conda ( conda install gunicorn ). 因此,我卸载了gunicorn( sudo apt-get purge gunicorn ),然后通过conda install gunicornconda install gunicorn )重新安装了它。 Now, when I run gunicorn ( gunicorn --bind 0.0.0.0:8000 wsgi:app ), I don't get a 50 line traceback. 现在,当我运行gunicorn( gunicorn --bind 0.0.0.0:8000 wsgi:app )时,我没有得到50行的回溯。 I do, however, get the following error: -bash: /usr/bin/gunicorn: No such file or directory . 但是,我确实得到以下错误: -bash: /usr/bin/gunicorn: No such file or directory I tried uninstalling gunicorn and reinstalling with pip, but I still get the same error. 我尝试卸载gunicorn并使用pip重新安装,但是仍然出现相同的错误。 I've tried searching Google and StackOverflow for solutions, but all I've discovered is that I should be installing gunicorn within a virtual environment to overcome this error (which, I beleive, I'm already doing). 我曾尝试在Google和StackOverflow上搜索解决方案,但发现的所有内容是,我应该在虚拟环境中安装gunicorn以克服此错误(我相信,我已经在这样做了)。 I'm guessing there's an easy fix to this, and that the problem is related to my ineptitude, as opposed to conda or something else. 我猜对此有一个简单的解决方法,问题出在我的虚弱上,而不是在conda或其他方面。 Any suggestions would be much appreciated. 任何建议将不胜感激。 Thanks. 谢谢。

So, I was right - the problem is entirely related to my own ineptitude. 所以,我是对的-问题完全与我自己的无能有关。 Rather than deleting this question, though, I'm going to answer it myself and leave it here in case any future fledgling developers run into the same problem. 不过,我不会自己删除该问题,而是自己回答并留在这里,以防将来任何新手开发人员遇到相同的问题。 The issue, as it turns out, is that I was running gunicorn --bind 0.0.0.0:8000 wsgi:app in the wrong directory. 事实证明,问题是我在错误的目录中运行gunicorn --bind 0.0.0.0:8000 wsgi:app After I cd into the directory containing wsgi.py , gunicorn works just fine. 我经过cd到包含目录wsgi.py ,gunicorn工作得很好。 The takeaway: gunicorn must be run from within the directory containing wsgi.py . 要点:gunicorn必须在包含wsgi.py的目录中wsgi.py

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

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