如何在 Ubuntu 上安装 Python 的 distutils?

发布于 2024-09-25 04:37:19 字数 1356 浏览 7 评论 0原文

我刚刚在 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 的 distutilssetuptools 的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

季末如歌 2024-10-02 04:37:20

找不到模块可能意味着软件包未安装。

Debian 已确定 distutils 不是核心 python 软件包,因此它不包含在最新版本的 debian 和基于 debian 的操作系统中。你应该能够做到

sudo apt-get install python3-distutils
sudo apt-get install python3-apt

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

sudo apt-get install python3-distutils
sudo apt-get install python3-apt
海风掠过北极光 2024-10-02 04:37:20

如果您使用的是最新版本的 Ubuntu 之一(或 Linux Mint 等变体),即附带 Python 3.8 的版本,那么您将无法使用 Python3.7 distutils,别名无法在 Python 3.7 中使用 pippipenv,请参阅:
如何为旧 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 use pip or pipenv with Python 3.7, see:
How to install python-distutils for old python versions

Obviously using Python3.8 is no problem.

随波逐流 2024-10-02 04:37:20

这对我不起作用: 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

贪了杯 2024-10-02 04:37:20

distutils 包提供了对构建附加模块并将其安装到 Python 安装中的支持。 Python 官方页面了解更多信息:此处

现在,在浏览上述链接时,我了解到 setuptools 是 distutils 的增强替代品。

因此,尝试使用以下命令下载 setuptools 而不是 disutils:

pip install setuptools

并且我没有再收到有关 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:

pip install setuptools

and I got no more error regarding distutils not found. The program worked successfully!

风轻花落早 2024-10-02 04:37:20

如果系统 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.

等风来 2024-10-02 04:37:20

通过搜索所有 python-distutils 相关包:

apt-cache search x

我得到 python3-distutils-extra - optimizations to the Python3 build system

然后尝试:

sudo apt-get install python3-distutils-extra

By searching all python-distutils related package:

apt-cache search x

I get python3-distutils-extra - enhancements to the Python3 build system

Then just try:

sudo apt-get install python3-distutils-extra
z祗昰~ 2024-10-02 04:37:19

在基于 Debian 的发行版(例如 Ubuntu)上,大多缺少 distutils 软件包。仅包根目录和 distutils.version 可用。其余代码已移至 python3-distutils,必须单独安装。

以下命令应该可以解决 Ubuntu 18.04、20.04 和 22.04 中的问题:

sudo apt-get install python3-distutils

如果您使用的是特定的 python3 次要版本,与发行版 python3 默认值不同,那么您可能需要安装系统 distutils 软件包的相应次要版本。例如,对于Python 3.10:

sudo apt-get install python3.10-distutils

参考Debian/Ubuntu 上的 Python 用户体验不佳 - distutils 被精简并缺少大部分代码

On Debian-based distros such as Ubuntu, the distutils package is mostly missing. Only the package root and distutils.version is available. The remaining code has been moved to python3-distutils, which must be installed separately.

The following command should solve the problem in Ubuntu 18.04, 20.04 and 22.04:

sudo apt-get install python3-distutils

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:

sudo apt-get install python3.10-distutils

reference: Negative Python user experience on Debian/Ubuntu - distutils is stripped down and missing most code.

难以启齿的温柔 2024-10-02 04:37:19

如果您无法使用其中任何一个进行安装:

sudo apt-get install python-distutils
sudo apt-get install python3-distutils

请尝试以下操作:

sudo apt-get install python-distutils-extra

参考:https: //groups.google.com/forum/#!topic/beagleboard/RDlTq8sMxro

If you are unable to install with either of these:

sudo apt-get install python-distutils
sudo apt-get install python3-distutils

Try this instead:

sudo apt-get install python-distutils-extra

Ref: https://groups.google.com/forum/#!topic/beagleboard/RDlTq8sMxro

不必在意 2024-10-02 04:37:19

您可以通过root权限使用sudo apt-get install python3-distutils

我相信它在这里有效

you can use sudo apt-get install python3-distutils by root permission.

i believe it worked here

神经暖 2024-10-02 04:37:19

您可以安装python-distutils包。 sudo apt-get install python-distutils 应该就足够了。

You can install the python-distutils package. sudo apt-get install python-distutils should suffice.

凉风有信 2024-10-02 04:37:19

当 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.

无法言说的痛 2024-10-02 04:37:19

我在使用标准 Angstrom 发行版的 Beaglebone Black 上遇到了这个错误。它当前运行的是Python 2.7.3,但不包括distutils。我的解决方案是安装 distutils。 (它需要 su 权限。)

    su
    opkg install python-distutils

安装后,之前出错的命令运行良好。

    python setup.py build

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.)

    su
    opkg install python-distutils

After that installation, the previously erroring command ran fine.

    python setup.py build
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文