Army of Earth
Army of Earth

Reputation: 311

wsl ubuntu 20.04 -> with python3.9 and without python3.8

Want to use python3.9 with actual pip and venv. And remove python3.8. I've installed python3.9 like that. Then pip. And python3.9-venv using apt.

Problem is pip and venv use distutils. Whish downloads via python3-distutils (python3.9-distutils is virtual package which refers to python3-distutils) and drags python3.8 with it.

I tried to remove python3.8 with all that methods one by one. But each time distutils removes along with python3.8. I read that dialogue. And I'm not quite sure but it seems there is no distutils outside of python3.8 package.

So am I nailed forever with python3.8 or there is solution to remove it safely? Or somehow extract distutils and tie it with python3.9?

Upvotes: 0

Views: 4611

Answers (1)

Emil Carpenter
Emil Carpenter

Reputation: 2129

Do not remove the system Python

The Ubuntu 20.04 system needs Python 3.8 for its own functionality. The system Python, in this case Python 3.8, should not be removed, because that can make the system instable.

Python 3.8 does not need to be removed to use Python 3.9.

More info here: https://unix.stackexchange.com/questions/652299/changing-pythons-default-version-breaks-ubuntu-20-04

No need for python3.9-distutils

python3-distutils works for both Python 3.8 and Python 3.9, no need for python3.9-distutils.

Source: https://github.com/deadsnakes/issues/issues/150#issuecomment-761180428

Create a venv virtual environment with Python 3.9

yourname@machine:~$ python3.9 -m venv /home/yourname/.venvs/my-venv-name

Activate the virtual environment:

yourname@machine:~$ source /home/yourname/.venvs/my-venv-name/bin/activate

Check the python version, it should be 3.9:

(my-venv-name) yourname@machine:~$ python -V
Python 3.9.9

Check the pip version within the venv, it is probably different than the system pip version:

(my-venv-name) yourname@machine:~$ pip3 --version
pip 21.2.4 from /home/yourname/.venvs/my-venv-name/lib/python3.9/site-packages/pip (python 3.9)

Deactivate the virtual environment:

(my-venv-name) yourname@machine:~$ deactivate

Check the system pip version, outside any venv:

yourname@machine:~$ pip3 --version
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)

Upvotes: 2

Related Questions