如何在 Ubuntu 上安装 Python 的 distutils?
我刚刚在 VPS 服务器上获得了一些空间(在 Ubuntu 8.04 上运行),我正在尝试在其上安装 Django。服务器安装了 python 2.5。当我运行 Django 安装脚本时,我得到:
amitoj@ninja:~/Django-1.2.1$ python setup.py install
Traceback (most recent call last):
File "setup.py", line 1, in <module>
from distutils.core import setup
ImportError: No module named distutils.core
我发现了很多关于如何使用 distutils 安装包的信息;但我如何获得 distutils 本身呢?
请注意Setuptools 包含 distutils 的修改版本,其中包含从未属于原始 distutils 的子模块。请参阅 stdlib 的 distutils 与 setuptools 的 distutils。当需要这些子模块时,无论如何都必须安装Setuptools。
另请注意,对于 Python 3.12 及以上版本需要Setuptools 才能获得此功能,因为 Distutils 已被从标准库中删除。请参阅为什么我收到错误 ModuleNotFoundError:没有名为“distutils”的模块?。在虚拟环境中也可能有必要,如 Windows:ModuleNotFoundError:没有名为“distutils”的模块。
但是,如果您在 Ubuntu 上有一个普通的 Python 发行版(3.11 或更早版本),以及一个 setup.py
或其他正在寻找标准 distutils< 的代码, /code> 功能 - 问题是 Ubuntu 维护者没有将其包含在捆绑的 Python 中。它需要使用系统包管理器进行安装,如此处答案中所述。
I just got some space on a VPS server(running on Ubuntu 8.04), and I'm trying to install Django on it. The server has python 2.5 installed. When I run the Django installation script, I get:
amitoj@ninja:~/Django-1.2.1$ python setup.py install
Traceback (most recent call last):
File "setup.py", line 1, in <module>
from distutils.core import setup
ImportError: No module named distutils.core
I found plenty of information about how to install packages using distutils; but how do I get distutils itself?
Note that Setuptools includes a modified version of distutils that includes sub-modules which were never part of the original distutils. See stdlib's distutils vs setuptools' distutils. When these sub-modules are needed, Setuptools must be installed anyway.
Also note that Setuptools is needed to get this functionality for Python 3.12 onward, because Distutils has been removed from the standard library. See Why did I get an error ModuleNotFoundError: No module named 'distutils'?. It may also be necessary within virtual environments, as in Windows: ModuleNotFoundError: No module named 'distutils'.
However, if you have an ordinary Python distribution, 3.11 or older, which came with the system, on Ubuntu, and a setup.py
or other code which is looking for the standard distutils
functionality - the problem is that the Ubuntu maintainers have not included it with the bundled Python. It needs to be installed using the system package manager, as described in answers here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
找不到模块可能意味着软件包未安装。
Debian 已确定 distutils 不是核心 python 软件包,因此它不包含在最新版本的 debian 和基于 debian 的操作系统中。你应该能够做到
The module not found likely means the packages aren't installed.
Debian has decided that distutils is not a core python package, so it is not included in the last versions of debian and debian-based OSes. You should be able to do
如果您使用的是最新版本的 Ubuntu 之一(或 Linux Mint 等变体),即附带 Python 3.8 的版本,那么您将无法使用 Python3.7
distutils
,别名无法在 Python 3.7 中使用pip
或pipenv
,请参阅:如何为旧 python 版本安装 python-distutils
显然使用Python3.8是没有问题的。
If you are in a scenario where you are using one of the latest versions of Ubuntu (or variants like Linux Mint), one which comes with Python 3.8, then you will NOT be able to have Python3.7
distutils
, alias not be able to usepip
orpipenv
with Python 3.7, see:How to install python-distutils for old python versions
Obviously using Python3.8 is no problem.
这对我不起作用:
sudo apt-get install python-distutils
所以,我尝试了这个:
sudo apt-get install python3-distutils
This didn't work for me:
sudo apt-get install python-distutils
So, I tried this:
sudo apt-get install python3-distutils
distutils 包提供了对构建附加模块并将其安装到 Python 安装中的支持。 Python 官方页面了解更多信息:此处。
现在,在浏览上述链接时,我了解到 setuptools 是 distutils 的增强替代品。
因此,尝试使用以下命令下载 setuptools 而不是 disutils:
并且我没有再收到有关 distutils not find 的错误。程序成功了!
The distutils package provides support for building and installing additional modules into a Python installation. Python's official page for further info: here.
Now while going through the above link I learnt that setuptools is an enhanced alternative to distutils.
So try to download setuptools instead of disutils with:
and I got no more error regarding distutils not found. The program worked successfully!
如果系统 Python 被中断(即操作系统包将 distutils 拆分到 python-devel 包中)并且您无法要求系统管理员安装缺少的部分,那么您将必须安装自己的 Python。它需要一些头文件和编译器工具链。如果您没有这些,请尝试在同一台计算机上编译 Python 并复制它。
If the system Python is borked (i.e. the OS packages split distutils in a python-devel package) and you can’t ask a sysadmin to install the missing piece, then you’ll have to install your own Python. It requires some header files and a compiler toolchain. If you can’t have those, try compiling a Python on an identical computer and just copying it.
通过搜索所有 python-distutils 相关包:
我得到 python3-distutils-extra - optimizations to the Python3 build system
然后尝试:
By searching all python-distutils related package:
I get python3-distutils-extra - enhancements to the Python3 build system
Then just try:
在基于 Debian 的发行版(例如 Ubuntu)上,大多缺少
distutils
软件包。仅包根目录和distutils.version
可用。其余代码已移至python3-distutils
,必须单独安装。以下命令应该可以解决 Ubuntu 18.04、20.04 和 22.04 中的问题:
如果您使用的是特定的 python3 次要版本,与发行版 python3 默认值不同,那么您可能需要安装系统 distutils 软件包的相应次要版本。例如,对于Python 3.10:
参考:Debian/Ubuntu 上的 Python 用户体验不佳 - distutils 被精简并缺少大部分代码。
On Debian-based distros such as Ubuntu, the
distutils
package is mostly missing. Only the package root anddistutils.version
is available. The remaining code has been moved topython3-distutils
, which must be installed separately.The following command should solve the problem in Ubuntu 18.04, 20.04 and 22.04:
If you're using a specific python3 minor version, different from the distro python3 default, then you may need to install the corresponding minor version of the system distutils package. E.g. for Python 3.10:
reference: Negative Python user experience on Debian/Ubuntu - distutils is stripped down and missing most code.
如果您无法使用其中任何一个进行安装:
请尝试以下操作:
参考:https: //groups.google.com/forum/#!topic/beagleboard/RDlTq8sMxro
If you are unable to install with either of these:
Try this instead:
Ref: https://groups.google.com/forum/#!topic/beagleboard/RDlTq8sMxro
您可以通过root权限使用
sudo apt-get install python3-distutils
。我相信它在这里有效
you can use
sudo apt-get install python3-distutils
by root permission.i believe it worked here
您可以安装
python-distutils
包。 sudo apt-get install python-distutils 应该就足够了。You can install the
python-distutils
package.sudo apt-get install python-distutils
should suffice.当 setuptools 尚不存在且无法使用包管理器时,安装 setuptools 的最简单方法是下载 ez_setup.py 并使用适当的 Python 解释器运行它。即使您有多个版本的 Python,这也有效:只需对每个 Python 运行一次 ez_setup.py 即可。
编辑:请注意,Python 3 的最新版本在发行版中包含了 setuptools,因此您不再需要单独安装。这里提到的脚本仅与旧版本的Python相关。
The simplest way to install setuptools when it isn't already there and you can't use a package manager is to download ez_setup.py and run it with the appropriate Python interpreter. This works even if you have multiple versions of Python around: just run ez_setup.py once with each Python.
Edit: note that recent versions of Python 3 include setuptools in the distribution so you no longer need to install separately. The script mentioned here is only relevant for old versions of Python.
我在使用标准 Angstrom 发行版的 Beaglebone Black 上遇到了这个错误。它当前运行的是Python 2.7.3,但不包括distutils。我的解决方案是安装 distutils。 (它需要 su 权限。)
安装后,之前出错的命令运行良好。
I ran across this error on a Beaglebone Black using the standard Angstrom distribution. It is currently running Python 2.7.3, but does not include distutils. The solution for me was to install distutils. (It required su privileges.)
After that installation, the previously erroring command ran fine.