ModuleNotFoundError:没有名为“distutils.util”的模块
ModuleNotFoundError: No module named ‘distutils.util’
当您的 Ubuntu 机器没有distutils
安装该模块时,会出现错误“ModuleNotFoundError: No module named ‘distutils.util’”。要解决该错误,请运行sudo apt-get install python3-distutils
命令安装
distutils
模块。
由于没有将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
如果这没有帮助,请添加deadsnakes
PPA 并安装特定版本的
distutils
.
您可以通过发出python --version
命令来查看您的 Python 版本。
python --version
For example, my Python version is 3.10.4
, so I have to issue the
sudo apt-get install python3.10-distutils
command.
sudo add-apt-repository ppa:deadsnakes/ppa sudo apt update sudo apt-get install python3.10-distutils sudo apt-get install python3.10-apt
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.
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.