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