Why did I get an error ModuleNotFoundError: No module named 'distutils'?
Asked Answered
S

6

39

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

Where did I go wrong?


This question addresses the problem from the perspective of installing a library. For developing a library, see How can one fully replace distutils, which is deprecated in 3.10?.

Satiety answered 5/10, 2023 at 1:54 Comment(1)
S
52

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.

Sheen answered 5/10, 2023 at 1:57 Comment(6)
Thank you for your answer, it worked! But now I have another problem, it said [ ModuleNotFoundError: No module named 'imp' ]. Is there any module that I have to install?Satiety
Yes imp was also removed, and there is no backport that I'm aware of. You may have to downgrade Python version, it sounds like skfuzzy is not ready to run on Python 3.12 yet.Sheen
It looks like scikit-fuzzy has already fixed the distutils issue in #296 (Dec 2022) and the imp issue in #265 (Sep 2020), however the package hasn't had a release since 0.4.2 in Nov 2019. Perhaps you could install directly from this branch in the meantime.Sheen
I'm getting this error too. Deprecate it but don't remove it. It breaks projects. IIUC The benefit of npm is preventing everything from breaking as libraries are updated.Iorgos
Python downloads page python.org/downloadsIorgos
and what we use then to install packages because when i do python -m pip install distutils i got no output and the pip command still don't work and also when use the python -m pip install to install other packages i got no output but the installation is not done.Borzoi
D
18

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

Dorina answered 11/12, 2023 at 9:59 Comment(2)
In 3.12 you cannot install setuptools as it still uses distutilsInterferon
@Interferon that is simply incorrect. Setuptools provides its own, modified copy of distutils, exactly because the standard library can't be relied upon to provide it - and because it needs to patch some issues in that code. While distutils wasn't formally deprecated until 3.10 (and thus removed in 3.12), it was supposed to have been phased out starting with 3.4 or so. As far as I'm aware, it wasn't being properly maintained all that time, either.Trainbearer
W
11

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

Walburga answered 10/3 at 15:24 Comment(2)
This worked for me in MacCzechoslovakia
Works for me on WIndows, thanks.Fop
P
6
brew install python-setuptools

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

Papyraceous answered 4/3 at 23:55 Comment(2)
Great this works for me. I used homebrew installed python (Python 3.12.2)Ravage
unfortunately this didn't work for me,Czechoslovakia
C
3

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.

Cowl answered 20/3 at 8:23 Comment(0)
M
1

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

xi python3-setuptools
Madera answered 18/3 at 20:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.