为什么我收到错误 ModuleNotFoundError:没有名为“distutils”的模块?

问题描述 投票:0回答:7

我已经安装了

scikit-fuzzy
,但是当我
import skfuzzy as fuzz
时,我收到错误

ModuleNotFoundError: No module named 'distutils'"

我已经尝试过

pip uninstall distutils
并得到了这个输出

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

然后我尝试再次安装

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

我哪里做错了?


这个问题从安装库的角度解决了这个问题。对于开发库,请参阅如何完全替换 distutils,它在 3.10 中已弃用?

python setuptools distutils skfuzzy python-3.12
7个回答
37
投票

Python 3.12 没有附带 stdlib distutils 模块 (changelog),因为

distutils
在 3.10 中已弃用并在 3.12 中被删除。请参阅 PEP 632 – 弃用 distutils 模块

您仍然可以通过安装

distutils
在 Python 3.12+ 上使用
setuptools

如果这不起作用,您可能需要继续使用 Python < 3.12 until the 3rd-party package (

skfuzzy
在这种情况下)发布了 Python 3.12 支持的更新版本。


13
投票

distutils
模块用于安装python包。该模块通常作为 python 安装的一部分安装。

在 python v3.12 中,删除了

distutils
模块。这意味着您本地没有任何工具来支持 python 包安装。

要解决此问题,请出于相同目的安装

setuptools

运行命令

python3 -m pip install setuptools


5
投票
brew install python-setuptools

如果您使用的是 mac 并使用 homebrew,则使用上面的命令安装缺少的模块


2
投票

我在导入tensorflow时也遇到了同样的问题。

我的解决方案是按照以下步骤操作,

  1. 安装安装工具
  2. 导入setuptools.dist

然后导入tensorflow,没有任何“ModuleNotFoundError”错误


0
投票

如果您使用的是 Void Linux,您可以通过运行以下命令来解决此问题:

xi python3-setuptools

0
投票

对于诗歌用户:

我在使用诗歌时遇到了同样的问题。

我在新机器上安装了 python 3.12,我的 pyproject.toml 说:

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

但是,它不够“智能”,无法检测到已安装没有 setuptools 的 python 3.12。

所以将诗改为

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

和跑步

poetry lock
poetry install

让一切恢复正常。


-5
投票

如果你发现这个错误,

ModuleNotFoundError: No module named 'distutils'
这意味着你的Python中缺少一些库。首先你打开终端并写入。

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

© www.soinside.com 2019 - 2024. All rights reserved.