What happened
During development, I encountered a problem:
Project code is written in python3 environment, but, in the terminal flask run
while running the project, but it is used python2 environment, resulting in many packages need to be reinstalled, and even some packages can not be installed.
How to solve it
There is a directory under the project venu
directory, which is a virtual environment!
If not, you can build one:
-
Create a directory to store the virtual environment, and enter the directory
mkdir venu cd venu
-
Download virtualenv
sudo apt install python3-virtualenv
-
Create a virtual environment based on the python version path
virtualenv -p /usr/bin/python3.8 venu3.8
Among them, venu3.8 is the name of the virtual environment I created
Activate the virtual environment:
Cd to the /venv/bin/
directory, execute the source activate
activation virtual environment!
effect:
Run the project in the terminal again, you can see that the environment has changed to python3!