1

I am not able to install distutils on my Ubuntu 22.04. I have just updated python from 3.10 to 3.11 as suggested here

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.11

and if I try to install the distutils this is what I get:

$ sudo apt-get install python3.11-distutils
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'python3-distutils' instead of 'python3.11-distutils'
python3-distutils is already the newest version (3.10.8-1~22.04).
0 upgraded, 0 newly installed, 0 to remove and 17 not upgraded.

As suggested, I tried to go through virtual env from $HOME, but I get the error:

$ python3.11 -m venv venv-py311 --system-site-packages
Error: Command '['/home/user/venv-py311/bin/python3.11', '-m', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.

Edit: I've fixed the last issue by installing:

sudo apt-get install python3.11-venv

Anyway, once in the venv, I still get the error:

$ python3.11 -m venv venv-py311 --system-site-packages
ERROR: Could not find a version that satisfies the requirement distutils (from versions: none)
ERROR: No matching distribution found for distutils
3
  • 2
    When you say you 'updated' python from 3.10 to 3.11, what do you mean? Did you replace the system Python with 3.11 on 22.04? If you did you're introducing massive breakage to your system. Commented Oct 27, 2025 at 21:07
  • @ThomasWard I have edited the post to make it clearer, hope it's not an issue. Commented Oct 27, 2025 at 21:11
  • 1
    are you sure that distutils isnt' already installed on the python 3.11 environment? python3-distutils is not a Deadsnakes PPA package, it's an Ubuntu specific package. Commented Oct 27, 2025 at 22:00

1 Answer 1

5

Unfortunately, the deadsnakes PPA does not reflect the vast number of packages that are from PyPI or other parts of the Ubuntu libraries and thus does not have individual packages such as python3-distutils for their versions.

This said, in Python 3.11, distutils is part of the standard Python libraries, so it's quite possible it is already included in the Deadsnakes PPA version of Python 3.11 without an extra package.

If not, you'll have to see if there's a version of it available in PyPI (which there may not be).

(Note that distutils is gone in Python 3.12 and later, so anything using it won't work if you go to even newer Python)


For this, you'll probably have to create a virtual environment for you to utilize and then install distutils with PyPI / pip.

1) Create a virtual environment for Python 3.11 (aka a 'venv').

I do this for myself and have a virtual environment that doesn't touch the system packages for updating and installing from PyPI and then I execute that in my login shell.

To create the environment like I have, you can do cd $HOME && python3.11 -m venv venv-py311 --system-site-packages

This will create a new directory in your home directory at venv-py311. From there, you can run source $HOME/venv-py311/bin/activate to activate the virtual environment.

You can also add that to the end of your .bashrc so every login shell on the terminal you use will have that.

2) Install distutils inside the venv.

Now that you have the venv and have activated it, you can simply run python3 -m pip install distutils which will then install distutils in the Python 3.11 virtual environment space.


Wait, what about doing this system-wide, and NOT using a venv?

Unfortunately, we have to defer to PEP668 and the Python rules on "Externally Managed Environments" (the full content of which you can read here). What this basically means is that if your Python installation is managed by apt or dpkg (which it is since you're using the Deadsnakes PPA and apt to install/remove it), the Python environment is configured to yell at you so you don't accidentally update something with pip or yourself that will break your entire system environment.

This is why I had you create a virtual environment to run from first. If you really want to make changes to this without the venv, then without doing step 1 and 2, you can run python3.11 -m pip install --break-system-packages distutils which will install distutils from PyPI in your Python 3.11 environment system-wide (in /usr/local/... space). This technically won't break your system packages, but for your Python 3.11 libraries (which are DIFFERENT than the default python3 aka Python 3.10 in your system), but because of PEP 668 and handling of Externally Managed Environments, you have to do this workaround.

DO NOT follow this bit if you are using a system-wide default Python installation in your system, because you will run the high risk of breaking things at that point.

1
  • Comments have been moved to chat; please do not continue the discussion here. Before posting a comment below this one, please review the purposes of comments. Comments that do not request clarification or suggest improvements usually belong as an answer, on Ask Ubuntu Meta, or in Ask Ubuntu Chat. Comments continuing discussion may be removed. Commented Oct 30, 2025 at 18:16

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.