ModuleNotFoundError: No module named 'distutils.util' [Fix]

avatar
Borislav Hadzhiev

Last updated: Apr 10, 2024
2 min

banner

# ModuleNotFoundError: No module named 'distutils.util'

The error "ModuleNotFoundError: No module named 'distutils.util'" occurs when your Ubuntu machine doesn't have the distutils module installed.

To solve the error, run the sudo apt-get install python3-distutils command to install the distutils module.

modulenotfounderror no module named distutils cmd

The three common errors that are caused by not having the distutils module installed alongside Python are:

  • "ModuleNotFoundError: No module named 'distutils.util'".
  • "ModuleNotFoundError: No module named 'distutils.cmd'".
  • "ModuleNotFoundError: No module named 'distutils.core'".
The solution to both errors is the same - we have to install the distutils module.

Open your terminal and run the following commands.

shell
sudo apt update sudo apt install python3-distutils sudo apt install python3-apt # ๐Ÿ‘‡๏ธ For Python 3.10 (scoped to specific version) sudo apt install python3.10-distutils # ๐Ÿ‘‡๏ธ For Python 3.11 sudo apt install python3.11-distutils

The distutils module is a part of the Python standard library so it has to be installed on your Ubuntu machine to be able to use Python.

If you get the "ModuleNotFoundError: No module named 'pip'", check out my other article with instructions on how to install pip.

If the error is not resolved, try reinstalling the distutils package.

shell
sudo apt-get install --reinstall python3-distutils # ๐Ÿ‘‡๏ธ For Python 3.10 sudo apt-get install --reinstall python3.10-distutils # ๐Ÿ‘‡๏ธ For Python 3.11 sudo apt-get install --reinstall python3.11-distutils

If that didn't help, add the deadsnakes PPA and install a specific version of distutils.

You can view your Python version by issuing the python --version command.

shell
python --version

get python version

For example, my Python version is 3.10.4, so I have to issue the sudo apt-get install python3.10-distutils command.

shell
sudo add-apt-repository ppa:deadsnakes/ppa sudo apt update sudo apt-get install python3.10-distutils sudo apt-get install python3.10-apt
If your Python version is 3.9.X, you would issue the sudo apt-get install python3.9-distutils command.

If the suggestion didn't help try reinstalling the distutils package scoped to your specific Python version.

shell
sudo apt-get install --reinstall python3.10-distutils

Make sure to update the version in the command according to the output of the python --version command.

If you get any errors related to pip, install pip by following the instructions in my ModuleNotFoundError: No module named 'pip' in Python article.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev