One can use conda
to create a virtual environment with Python 3.8:
conda create -n py38test1 python=3.8
conda activate py38test1
Otherwise, one can use pyenv
. To install pyenv
:
# Install pyenv following the instructions from https://github.com/pyenv/pyenv-installer
curl https://pyenv.run | bash
# Run nano ~/.bashrc
# Add the following at the end
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
# Save file and run:
exec $SHELL
Running pyenv install --list | grep " 3\.[678]"
will display the available python versions:
[...]
3.8
3.8-dev
[...]
To install python 3.8 in pyenv
:
# To avoid the common issue "ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?" (https://github.com/pyenv/pyenv/wiki/Common-build-problems#error-the-python-ssl-extension-was-not-compiled-missing-the-openssl-lib)
sudo apt-get install libssl-dev
# To avoid the common issue "WARNING: The Python readline extension was not compiled. Missing the GNU readline lib?" (https://github.com/pyenv/pyenv/wiki/Common-build-problems#error-the-python-ssl-extension-was-not-compiled-missing-the-openssl-lib)
apt-get install -y libreadline-dev
# Install the python target version
pyenv install 3.8.12
To create a new pyenv
virtual environment with python 3.8:
# Create a virtual environment with python 3.8:
pyenv virtualenv 3.8.12 test
To activate the virtual environment test
:
pyenv activate test
eval "$(pyenv init --path)" # to activate python 3.8.12
(The additional eval "$(pyenv init --path)"
is because of this issue.)
To deactivate the virtual environment:
pyenv deactivate
FYI, useful commands:
- To view the installed python versions in
pyenv
: pyenv versions