使用python3而不是python运行Flask [英] Run Flask using python3 not python
问题描述
如何运行使用特定版本python的Flask应用?
How can you run Flask app which uses a specific version of python?
在我的环境中,"python" = python2.7和"python3" = python3.6.我已经使用pip3安装了Flask.我用FLASK_APP=app.py flask run
启动该应用程序.它使用python2.7执行,我希望它使用python3.6.
On my env "python" = python2.7 and "python3" = python3.6. I have installed Flask using pip3. I start the app with FLASK_APP=app.py flask run
. It uses python2.7 to execute, I would like it to use python3.6.
还尝试将#!flask/bin/python3
添加到app.py,但没有效果.
Also tried adding #!flask/bin/python3
to app.py, but it did not have an effect.
推荐答案
有几种方法:
-
Virtualenv 可让您创建具有不同版本的隔离python环境(这是我推荐的方式)
Virtualenv lets you create isolated python environments with different versions (this is the way I would recommend)
您可以将#!/usr/bin/python3
放在python文件的顶部(请参见此处)
You can put #!/usr/bin/python3
on top of your python file (see here)
或者您可以使用python3 script.py
如上所述,您还可以在托管python3安装的Docker容器
As mentioned in the comments above you can also start your script inside a Docker container that hosts a python3 installation
这篇关于使用python3而不是python运行Flask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!