我正在尝试在Amazon EC2实例上设置flask。 我想从已安装的虚拟环境中运行带有python 3.5的烧瓶。
但是,当我运行flask时,它正在使用ubuntu python 2.7安装。
如何告诉flask使用虚拟环境python安装?
谢谢
I'm trying to setup flask on an Amazon EC2 instance. I want to run flask with python 3.5 from an installed virtual environment.
However when I run flask it is using the ubuntu python 2.7 installation.
How do I tell flask to use the virtual environment python installation?
Thanks
最满意答案
如果您在开发期间从CLI运行它,那么您的服务器上应该已经安装了python 3.5。 如果没有,那么运行sudo apt-get install python3 。 要运行应用程序:
python3 app.py
但是,因为你问的是virtualenv - 这是非常好的练习 - 你可以创建一个指定python3路径的新环境,如下所述。 如果您不知道路径,请运行which python3 。 对于我的电脑,运行Ubuntu 16.04:
virtualenv -p /usr/bin/python3 <path/to/new/virtualenv/>
然后:
source <env_name>/bin/activate
现在,即使对于开发人员来说,这也不是一个非常好的设置,并且对于制作而言绝对可怕。 我建议使用uWSGI和NGINX来为您的应用程序提供服务。 您可以在uWSGI配置中指定virtualenv路径 - 我建议使用.ini文件。 这是一个非常好的数字海洋教程,我曾经开始使用。 它不会教你一切,但它应该让你走上正确的道路。 这种配置在线有很多资源,因此您应该能够解决遇到的任何问题。
If you're running this from the CLI during development, you should already have python 3.5 on your server. If not then run sudo apt-get install python3. To run the app:
python3 app.py
However, since you are asking about virtualenv--which using is very good practice--you could create a new environment specifying the path of python3, as stated here. If you don't know the path, run which python3. For my computer, running Ubuntu 16.04:
virtualenv -p /usr/bin/python3 <path/to/new/virtualenv/>
Then:
source <env_name>/bin/activate
Now, this is not a very good setup even for dev and would be absolutely terrible for production. I would suggest using uWSGI and NGINX to serve your app. You can specify your virtualenv path in your uWSGI config--I would suggest using a .ini file. Here is a very good Digital Ocean tutorial that I used to get started. It won't teach you everything, but it should put you on the right path. There's a lot of resources for this configuration online, so you should be able to solve any problems you run into.
更多推荐
发布评论