121

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.

Neo
  • 13,179
  • 18
  • 55
  • 80

11 Answers11

254

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
Étienne
  • 4,773
  • 2
  • 33
  • 58
ettanany
  • 19,038
  • 9
  • 47
  • 63
  • 10
    This package literally does not exist in Ubuntu 16.04. https://packages.ubuntu.com/search?keywords=python3-distutils – Nicholi Sep 20 '18 at 21:00
  • 9
    Worked like a charm on 18.04 – habitats Feb 22 '19 at 11:00
  • 2
    Getting error E: Package 'python3-distutils' has no installation candidate in Ubuntu 18.4 – Ganesh Jun 07 '19 at 07:30
  • 1
    Same as @Ganesh, `has no installation candidate` Ubuntu 16.04.6 LTS – hugo blanc Nov 17 '19 at 17:18
  • I have this installed for python3.7 but when for python3.6 it shows no module found distutils.utils, What should I do? – Sarthak Kumar May 05 '20 at 12:21
  • 4
    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 – Lukas Oct 20 '20 at 17:09
  • For Ubuntu 16.04 is better to specify version. Like @Lukas mention above: `sudo apt-get install python3.8-distutils` -> fix my problem with `python3.8` – dannydedog Aug 05 '21 at 09:52
  • Thanks. It's one of the quick find for me in stackoverflow. – thulasi39 Apr 28 '22 at 08:56
30

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

Ben Amos
  • 1,750
  • 15
  • 18
  • 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)` – mLstudent33 Oct 30 '19 at 21:10
  • 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)` – mLstudent33 Oct 30 '19 at 21:11
  • What is the difference between `python3-distutils-extra`(on Ubuntu16.04) and `python3-distutils`(cannot locate on python3-distutils-extra)? – skytree Feb 10 '20 at 11:04
  • 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. – Ben Amos Feb 11 '20 at 00:24
16

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

i believe it worked here

Mohammad Heydari
  • 3,933
  • 2
  • 26
  • 33
13

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

Manoj Govindan
  • 72,339
  • 21
  • 134
  • 141
  • 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. – Neo Sep 28 '10 at 07:35
  • 3
    If you are installing local Python switch to 2.6 or 2.7 They come with `distutils` bundled. – Manoj Govindan Sep 28 '10 at 07:36
  • 2
    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. – merwok Oct 09 '11 at 10:11
  • 1
    It's now prepended with the python version, for me: `sudo apt install python3.8-distutils` – Seraf Aug 09 '22 at 12:35
9

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
mightypile
  • 7,589
  • 3
  • 37
  • 42
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.

Duncan
  • 92,073
  • 11
  • 122
  • 156
  • 3
    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. – Neo Sep 28 '10 at 08:06
  • 3
    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 May 13 '18 at 17:46
  • 1
    @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 May 14 '18 at 09:27
  • 7
    @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. – Jmills May 14 '18 at 21:05
  • 2
    It appears that 14.04, 16.04 both have it "built in" but in 18.04 you need to install `python3-distutils` FWIW... – rogerdpack Oct 09 '18 at 05:00
  • gives error for python3, `$ python3 ~/python_setup_tools/ez_setup.py File "/home/prashant/python_setup_tools/ez_setup.py", line 106 except pkg_resources.VersionConflict, e: ^ SyntaxError: invalid syntax` worked for python2 `$ python2 ~/python_setup_tools/ez_setup.py Setuptools version 0.6c11 or greater has been installed. (Run "ez_setup.py -U setuptools" to reinstall or upgrade.)` – Prashant Adlinge Aug 10 '22 at 09:30
7

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
Abdul Basit
  • 953
  • 13
  • 14
3

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.

Zoltan Fedor
  • 2,004
  • 2
  • 23
  • 40
2

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

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

Cyebukayire
  • 795
  • 7
  • 14
0

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
Frances He
  • 114
  • 1
  • 4
0

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.

merwok
  • 6,779
  • 1
  • 28
  • 42