Why did I got an error ModuleNotFoundError: No module named 'distutils'?

24.4k Views Asked by At

I've installed scikit-fuzzy but when I import skfuzzy as fuzz I get an error

ModuleNotFoundError: No module named 'distutils'"

I already tried to pip uninstall distutils and got this output

Note: you may need to restart the kernel to use updated packages.
WARNING: Skipping distutils as it is not installed.

Then I tried to install it again pip install distutils

Note: you may need to restart the kernel to use updated packages.
ERROR: Could not find a version that satisfies the requirement distutils (from versions: none)
ERROR: No matching distribution found for distutils

Since I use Python 3.12 I also tried to use pip3 to install but it say invalid syntax.

Where did I go wrong?

7

There are 7 best solutions below

5
wim On BEST ANSWER

Python 3.12 does not come with a stdlib distutils module (changelog), because distutils was deprecated in 3.10 and removed in 3.12. See PEP 632 – Deprecate distutils module.

You can still use distutils on Python 3.12+ by installing setuptools.

When that doesn't work, you may need stay on Python < 3.12 until the 3rd-party package (skfuzzy in this case) publishes an updated release for Python 3.12 support.

2
AKARSHIT MAURYA On

if you found this error the ModuleNotFoundError: No module named 'distutils' that mean some library missing in your python. firstly you open your terminal and write.

pip install setuptools pip install poetry pip install pipenv pip install --upgrade pip

1
Swetha Lakshmi On

distutils module is used to install python packages. This module usually installed as part of python installation.

In python v3.12, distutils module removed. This means your local doesn't have any tool in place to support python package installation.

To resolve this issue, install setuptools for same purpose.

Run the command python3 -m pip install setuptools

1
PDHide On
brew install python-setuptools

if you are using mac and use homebrew then use above command to install missing module

0
Suvo Pal On

I have also faced same issue while importing tensorflow.

My solution was to follow below steps,

  1. install setuptools
  2. import setuptools.dist

Then tensorflow was imported without any "ModuleNotFoundError" error

0
Randall Flagg On

If you are using Void Linux you can solve this by runnig the following command:

xi python3-setuptools
0
Ein Google-Nutzer On

For Poetry users:

I had the same problem while using poetry.

I had python 3.12 installed on a new machine and my pyproject.toml said:

[tool.poetry.dependencies]
python = "^3.11"

However, it was not "smart" enough to detect that python 3.12 is installed which has no setuptools.

So changing poetry to

[tool.poetry.dependencies]
python = "^3.12"

and running

poetry lock
poetry install

made everything work again.