When using Ubuntu in WSL you need to be careful about upgrading Python to something newer (for 20.04 LTS the default is Python 3.8) as it may affect system operations.
One solution I found keeps the system running with Python 3.8, and allows you to run Python 3.9 in a virtual environment.
sudo apt update
sudo apt install python3.9 python3.9-venv
venv
). Firstly create the venv
& path:
user@machine:~$ python3.9 -m venv /home/username/.venvs/<name of venv>
For my own clarity, and a basic environment, i've simply called mine py3_9
. Also in the command below, i've truncated the path to my homedir using the ~
character:
user@machine:~$ python3.9 -m venv ~/.venvs/py3_9
venv
:
user@machine:~$ source ~/.venvs/py3_9/bin/activate
(py3_9) user@machine:~$
(py3_9) user@machine:~$ python -V
Python 3.9.5
(py3_9) user@machine:~$ wget http://bootstrap.pypa.io/get-pip.py
(py3_9) user@machine:~$ python get-pip.py
(py3_9) user@machine:~$ pip3 --version
pip 22.2.2 from /home/username/.venvs/py3_9/lib/python3.9/site-packages/pip (python 3.9)
venv
with:
(py3_9) user@machine:~$ deactivate
Refs: