Age old python install issues, update python3-distils

I've had this problem many times and not been able to solve. I've just manually compiled and installed python 3.10 on ubuntu 20.04, for some reason think that latest is likely to be the best however with python this is debatable!

Now when I try to do some updates I get common errors such as these, suggests the system is not finding 'py_compile.py' ?

Setting up python3-distutils (3.8.10-0ubuntu1~20.04) ...
/usr/bin/python3.9: can't open file '/usr/lib/python3.9/py_compile.py': [Errno 2] No such file or directory

However when I search I have many copies of this file in my system including

/usr/local/lib/python3.10/py_compile.py

Where should this file be so the system will find it? Do I need to specify a different install directory for ubuntu, as opposed to most other linux systems, when configuring before the make, make install stages of compiling?

I won't even entertain using purge or anything like that, have removed large parts of the whole system before by doing this, everything seems to be dependent on python! Thx. J


py_compile.py is provided by libpython3.8-minimal in Ubuntu 20.04. Open the terminal and type:

sudo apt install python3-all libpython3.8-minimal
sudo update-alternatives --config python3 # select python3.8 for auto mode
sudo apt install python3-distutils
sudo apt update
sudo apt upgrade

In addition to the above code, you have broken symbolic links from versions of Python which you deleted, some of which were originally manually installed. These broken symbolic links to deleted versions of Python 3.X are causing apt (which requires python3) to behave improperly. You can find these broken symbolic links by following the instructions in How can I find broken symlinks.

If you find any suspicious looking symbolic links you can scan them with the symlinks package ( sudo apt install symlinks ) and search for any dangling links. dangling links are those for which the target of the link does not currently exist, so dangling links can be safely deleted. If you're unsure about whether a symbolic link can be safely deleted you can rename the link by appending a .bak extension at the end of its name, so that you can quickly restore the link by removing the .bak extension from its name.


The safest way to install python3.10 in Ubuntu 20.04 is to use the deadsnakes PPA.

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt install python3.10

And then call it with python3.10. For python3.9, install with sudo apt install python3.9.


You have not described what all changes you have done to your system (you seem to have python3.9 and python3.10).

In case you have not removed the default python version (3.8), you can reset the default version with update-alternatives --config python and choose python3.8.

In case you have already replaced the default version with python3.9, you will have to reinstall Ubuntu. The system components in Ubuntu 20.04 are designed to work with python3.8.