ModuleNotFoundError: No module named ‘distutils.util’

ModuleNotFoundError:没有名为“distutils.util”的模块

ModuleNotFoundError: No module named ‘distutils.util’

当您的 Ubuntu 机器没有distutils安装该模块时,会出现错误“ModuleNotFoundError: No module named ‘distutils.util’”。要解决该错误,请运行sudo apt-get install python3-distutils命令安装
distutils模块。

modulenotfounderror 没有名为 distutils cmd 的模块

由于没有将distutils模块与 Python 一起安装而导致的三个常见错误是:

  • “ModuleNotFoundError:没有名为‘distutils.util’的模块”
  • “ModuleNotFoundError:没有名为‘distutils.cmd’的模块”
  • “ModuleNotFoundError:没有名为‘distutils.core’的模块”
这两个错误的解决方案是相同的——我们必须安装该模块。 distutils

打开终端并运行以下命令。

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

distutils模块是 Python 标准库的一部分,因此必须将其安装在您的 Ubuntu 机器上才能使用 Python。

如果您收到“ModuleNotFoundError:没有名为‘pip’的模块”,
请查看我的另一篇文章,其中包含有关如何安装 pip 的说明

如果错误未解决,请尝试重新安装distutils软件包。

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

如果这没有帮助,请添加deadsnakesPPA 并安装特定版本的
distutils.

您可以通过发出python --version命令来查看您的 Python 版本。

python --version

获取 python 版本

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.