The python version is high, use the virtual environment to downgrade the version

During the development, you will encounter that the python dependencies used in the previous old projects are based on low versions. If you install and use them in a python environment above 3.10, various incompatibility problems will be prompted. So I thought of downgrading the version, but in order to minimize the impact, I thought of a virtual environment.

You need to use pyenv to downgrade the version, and you need to use virtualenv in the virtual environment, but virtualenv can only use the main version of python. Even if you use pyenv to downgrade the python version to 3.8.15, the virtual environment created with virtualenv will still use the system version .

So you need to use pyenv-virtualenv.

After installation, you need to modify the ~/.bashrc file and add the following two sentences

eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

Use it afterwards source ~/.bashrcto make the configuration take effect.

At this point, you can use it pyenv virtualenv 3.8.15 py3815to create a virtual environment of version 3.8.15.
Enter the virtual environment by pyenv virtualenvsviewing the existing virtual environment
pyenv activate py3815, and use python -Vthe python version to view the current environment.

At this time, the virtual environment is version 3.8.15, and the external version is still version 3.10.x.
At this time, if you go to install the dependencies again, you will not report an error.

Guess you like

Origin blog.csdn.net/qq_28992047/article/details/128144561