how to install python distutils

Question:

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, but I guess its non standard installation. When I run install script for django, 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’m stumped. All the articles on internet tell me how to install modules using distutils. But how do I get distutils itself? Can anyone point me to the archive for distutils? I looked in /usr/lib/local/python2.5, /usr/lib/python2.5 etc, and as expected there is no distutils to be found.

Asked By: Neo

||

Answers:

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

Answered By: Manoj Govindan

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.

Answered By: Duncan

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.

Answered By: merwok

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
Answered By: mightypile

I know this is an old question, but I just come across the same issue using Python 3.6 in Ubuntu, and I am able to solve it using the following command (this works in Ubuntu 18.04, 20.04 and 22.04):

sudo apt-get install python3-distutils
Answered By: ettanany

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

i believe it worked here

Answered By: Mohammad Heydari

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

Answered By: Ben Amos

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.

Answered By: Zoltan Fedor

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
Answered By: Frances He

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
Answered By: Abdul Basit

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

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

Answered By: Cyebukayire
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.