ModuleNotFoundError: No module named 'distutils.util'

The module not found likely means the packages aren't installed.

sudo apt-get install python3-distutils

sudo apt-get install python3-apt

If they're already installed you can try to fix anything that may have been messed up in the upgrade with...

sudo apt-get install --reinstall package-name

I got this problem after upgrading to Ubuntu 20.04. I had a virtual environment depending on Python 3.7, and, to avoid re-installing the whole virtual environment for Python 3.8, I fixed distutils on Python 3.7:

I added the deadsnake PPA:

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update

And then installed the distutils package for Python 3.7:

sudo apt install python3.7-distutils

Note: for some reason I had an error installing the latter, that I solved this way:

sudo dpkg -i --force-overwrite /var/cache/apt/archives/python3.7-distutils_3.7.9-1+focal1_all.deb
sudo apt-get -f install 

Debian has decided that distutils is not a core python package, so it is not included in the last versions of debian and debian-based OSes. You should be able to do sudo apt install python3-distutils and it should work.

However, it did not work for me. I use Parrot OS, which is, as Ubuntu, Debian based. I upgraded my system and pip stopped working for python3.7, and I also got the error ModuleNotFoundError: No module named 'distutils.util'

I tried a lot of stuff to fix it and to reinstall distutils, and I found out by pure luck, that pip3, for python3.8 did work. I then tried python3.7 -m pip3 -V, got /usr/bin/python3.7: No module named pip3 so I decided to have a look in the /usr/lib files.

I looked at /usr/lib/python3/dist-packages and everything looked fine. Then I looked at /usr/lib/python3.7 and saw the folder distutil.

I opened it, and saw the __pycache__, the __init__.py file and a version.py file. I had no idea how many files should be in there, or what the code should be, but I knew that those two files were either wrong or missing another file.

Then I had a look at what was inside /usr/lib/python3.8/distutil and it was totally different. I found the following files:

command                          Folder
__pycache__                      Folder
archive_util.py                  Python script
bcppcompiler.py                  Python script
cmd.py                           Python script
config.py                        Python script
core.py                          Python script
cygwinccompiler.py               Python script
debug.py                         Python script
dep_util.py                      Python script
errors.py                        Python script
extension.py                     Python script
fancy_getopt.py                  Python script
filelist.py                      Python script
file_util.py                     Python script
__init__.py                      Python script
log.py                           Python script
msvc9compiler.py                 Python script
_msvccompiler.py                 Python script
msvccompiler.py                  Python script
README                           Plain text file
spawn.py                         Python script
sysconfig.py                     Python script
text_file.py                     Python script
unixccompiler.py                 Python script
util.py                          Python script
version.py                       Python script
versionpredicate.py              Python script

This was a lot more promising, and since pip3 did work, I assumed that this distutils worked too, and I tried to copy it to the python3.7 folder by running this command:

sudo cp -r /usr/lib/python3.8/distutils /usr/lib/python3.7/distutils

Alternatively:

sudo mv /usr/lib/python3.7/distutils/ /usr/lib/python3.7/distutils_back
sudo ln -s /usr/lib/python3.8/distutils /usr/lib/python3.7/

Then I tried again python3.7 -m pip -V and got

pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.7)

Then I tried installing some modules and everything works fine. I hope this is helpful.