129

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.

0

12 Answers 12

261

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.

Sign up to request clarification or add additional context in comments.

8 Comments

This package literally does not exist in Ubuntu 16.04. packages.ubuntu.com/search?keywords=python3-distutils
Worked like a charm on 18.04
Getting error E: Package 'python3-distutils' has no installation candidate in Ubuntu 18.4
Same as @Ganesh, has no installation candidate Ubuntu 16.04.6 LTS
It is possible to install it for the very specific version. I tried it with sudo apt-get install python3.9-distutils after the output for (...) python3-distutils told, it is up-to-date at version 3.6 although i set python3 to 3.9. and that worked
|
34

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

4 Comments

I'm getting an error: Errors were encountered while processing: oracle-java11-installer-local E: Sub-process /usr/bin/dpkg returned an error code (1)
but my java -version looks okay: java version "11.0.4" 2019-07-16 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.4+10-LTS) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.4+10-LTS, mixed mode)
What is the difference between python3-distutils-extra(on Ubuntu16.04) and python3-distutils(cannot locate on python3-distutils-extra)?
Per packages.debian.org: "This package (python3-distutils-extra) provides additional functions to Python's distutils and setuptools." So it would seem that distutils is a dependency of distutils-extra. Why installing distutils-extra would succeed where installing distutils fails, I cannot say.
15

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

i believe it worked here

1 Comment

This adds nothing that wasn't already covered in existing answers.
14

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

4 Comments

Can't do that. Its a VPS server, I don't have sudo privileges. I'm thinking of installing a local python. Either that, or I find distutils archive for python 2.5.
If you are installing local Python switch to 2.6 or 2.7 They come with distutils bundled.
All Python have included distutils since 1999. Here it looks like one of the stupid OSes that split the standard library into arbitrary python and python-devel packages.
It's now prepended with the python version, for me: sudo apt install python3.8-distutils
9

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.

7 Comments

Thanks for the reply, but it didn't work. I get this " import _md5 ImportError: No module named _md5" error. The basic python installation is pretty screwed up I guess. I'll go with local install. Thanks a lot anyway.
That script's syntax seems out of date. At the very least it won't run in python3.6, so not a great solution currently.
@Jmills Python from 3.4 onwards includes setuptools so no need to run that script on recent versions. The question was asked about Python 2.
@Duncan Oh yes it does say Python2 - so this error can be encountered installing Python3.6 on Ubuntu 16.04, that is what brought me here, and sudo apt-get install python3-distutils will fix it. But your note clarifies the version difference.
It appears that 14.04, 16.04 both have it "built in" but in 18.04 you need to install python3-distutils FWIW...
|
8

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

Comments

6

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

1 Comment

Correct, but adds nothing that existing answers didn't already cover.
2

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.

Comments

2

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!

1 Comment

@karel Yet surprisingly, no other answer mentions pip install setuptools, which I have had to do in some projects even in recent years (sometimes with a specific version), so this answer provides a small element of new information that has value.
1

This didn't work for me: sudo apt-get install python-distutils

So, I tried this: sudo apt-get install python3-distutils

Comments

-1

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.

Comments

-1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.