告诉Flask使用哪个虚拟环境(Tell Flask Which Virtual Environment To Use)

编程入门 行业动态 更新时间:2024-10-28 12:26:01
告诉Flask使用哪个虚拟环境(Tell Flask Which Virtual Environment To Use)

我正在尝试在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.

更多推荐

本文发布于:2023-07-15 05:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1110707.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:环境   Flask   Environment   Virtual

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!