Modulenotfounderror: no module named distutils.cmd

In this article, we will discuss the solutions to solve the error no module named distutils.cmd which is experience of several python programmers.

Also read the other solve error: Modulenotfounderror no module named conf [SOLVED]

Why the modulenotfounderror no module named ‘distutils.cmd’ Occurs?

The modulenotfounderror no module named ‘distutils.cmd’ occurs if you run the python script without installing the “distutils” module in your python library.

However it is installed the distutils yet it’s installed in an incorrect PATH environment variable.

If you trying to import the distutils module then your python interpreter cannot find it on your system then you will get the ModuleNotFoundError.

For example you import like this:

 from distutils import distutils.cmd

Then the output will be following below:

ModuleNotFoundError: no module named distutils.cmd

Common reasons why this error may occur:

  1. Missing module: The distutils.cmd module it should be missing from your Python library installation. This it will happen when you are using an older version of Python which is haven’t include in this module, or when the module was accidentally uninstall or removed.
  2. Incorrect installation: When you have recently installed Python or a module that uses distutils.cmd, it is possible that the installation was not completed successfully or it does not installed in the correct path environment location.
  3. Virtual environment issue: If you are running in a virtual environment, it is possible that the distutils.cmd module is haven’t installed in the virtual environment or it is installed in a different version of Python which is doesn’t used by the virtual environment.

How to solve the modulenotfounderror no module named ‘distutils.cmd’?

Time needed: 2 minutes

To solve the modulenotfounderror no module named ‘distutils.cmd’ error with the following solutions below:

  • Solution 1: Installation of the distutils module in windows

    The first solution is to install the distutils module in your python library. To install the “distutils” module is the most suitable option. Use a package manager, which is the “pip” command to install the required module library.

    Here is the following command:

    pip install distutils

  • Solution 2: Installation of the distutils module in Anaconda

    Here is the following command to install the distutils module in Anaconda:

    conda install distutils

  • Solution 3: Installation of the distutils module for Ubuntu / Debian

    Here is the following command to install the distutils module in Ubuntu / Debian:

    sudo apt-get install python3.9-distutils

Other Solutions to solve the error

When the error “modulenotfounderror: no module named distutils.cmd,” still persists, your Python script should be using a different version of “distutils” rather than the one you are using.

To resolve this error, you need to uninstall the “distutils” module and reinstall it using “pip” command or “conda” command for the Python version your script is using. 

Solution 1: Uninstall the “distutils” module

Here is the following command to uninstall:

pip uninstall distutils

Solution 2: Reinstall the “distutils” module

Here is the example command to reinstall for the specific version:

pip install distutils==3.7

Conclusion

In conclusion, I hope one of these solutions above will help you resolve the “ModuleNotFoundError: no module named distutils.cmd” error.

Leave a Comment