The python operating environment in Pycharm is inconsistent with the python operating environment in the terminal

What happened

During development, I encountered a problem:

Project code is written in python3 environment, but, in the terminal flask runwhile 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.
Insert picture description here
Insert picture description here

How to solve it

There is a directory under the project venudirectory, 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 activateactivation virtual environment!

effect:

Run the project in the terminal again, you can see that the environment has changed to python3!

Insert picture description here

Guess you like

Origin blog.csdn.net/WU2629409421perfect/article/details/114550790