简体   繁体   English

如何使Flask与Python 3兼容?

[英]How can I make Flask work with Python 3?

I have written an API in my personal machine and I want to make it run on a remote machine. 我已经在我的个人计算机上编写了一个API,我想使其在远程计算机上运行。

I have used Python 3 and flask with Pycharmm without any problems in my own machine. 我在自己的机器上将Python 3和flask与Pycharmm一起使用时没有任何问题。 However I connect the remote machine using ssh. 但是我使用ssh连接远程机器。 So it's impossible to configure environment with an IDE. 因此,用IDE配置环境是不可能的。

When I type flask --version the output is as below: 当我输入flask --version ,输出如下:

Flask 0.12.2 
Python 2.7.12 (default, Jul  1 2016, 15:12:24)  
[GCC 5.4.0 20160609]

Python 3 is installed. 已安装Python 3。 I have a choice to run the python script using python3 service.py . 我可以选择使用python3 service.py运行python脚本。 At that time I am given an error as ImportError: No module named 'flask' . 那时,我收到一个错误,如ImportError: No module named 'flask' When I use flask run I am given errors related to Python 2. I have used some features of Python 3 which are not included in Python 2. 当我使用flask run时,会flask run与Python 2相关的错误。我使用了Python 3中未包含的某些Python 3功能。

How can I configure Flask to run using Python 3 in that environment? 如何配置Flask在该环境中使用Python 3运行?

Try pip3 install flask . 尝试pip3 install flask Ideally you should be doing this in a virtual environment . 理想情况下,您应该在virtual environment执行此操作。 Also, you might want to look at dockerizing your code since it will help reduce conflict between different python versions. 另外,您可能希望对代码进行dockerizing因为这将有助于减少不同python版本之间的冲突。

As an addition I have installed the pip3 using apt-get install python3-pip 另外,我已经使用apt-get install python3-pip安装了pip3

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

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