0

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?

Army of Earth
  • 311
  • 2
  • 8

1 Answers1

2

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)

Emil Carpenter
  • 1,163
  • 10
  • 19
  • I already installed newest ```pip``` to system level... Should I unistall it and reinstall python3.8 (which probably contains ```pip```)? Also I dont have ```mkvirtualenv``` "command not found". Same as ```virtualenv```. I still able to proceed with ```python -m venv venv``` (python binded to python3.9). – Army of Earth Dec 21 '21 at 15:33
  • Okay... I found the issue with manualy installed ```pip``` at system level. ```pip``` doesn't exist at ```/usr/bin```. It still able to install but to unistall some packages I need SU rights, but ```sudo pip uninstall ...``` leads to *"sudo: pip: command not found"* – Army of Earth Dec 21 '21 at 16:39
  • 1
    Sorry about the `mkvirtualenv` and `virtualenv` commands. [virtualenv](https://pypi.org/project/virtualenv/) is another package for creating virtual environments, instead of [venv](https://docs.python.org/3/library/venv.html). `mkvirtualenv` is a command from [virtualenvwrapper](https://virtualenvwrapper.readthedocs.io/en/latest/), a set of extensions for `virtualenv` to manage virtual environments created by `virtualenv`. Corrected my answer for use with `venv` (removed instructions for using `virtualenv` through `virtualenvwrapper`). – Emil Carpenter Jan 03 '22 at 14:22