1 min read

Python Distutils Module

The distutils package provides support for building and installing additional modules into a Python installation. The new modules may be either 100%-pure Python, or may be extension modules written in C, or may be collections of Python packages which include modules coded in both Python and C.

Note: The distutils package is deprecated as of Python 3.10 and was removed in Python 3.12. Its functionality for specifying package builds has been replaced by setuptools and packaging.

Importing the Module

import distutils.core

Basic Usage (setup.py)

The core of distutils is the setup function. A typical setup.py script looks like this:

from distutils.core import setup

setup(name='MyApp',
      version='1.0',
      description='My Application',
      author='Me',
      author_email='me@example.com',
      url='https://www.example.com',
      packages=['myapp'],
     )

Common Commands

Once you have a setup.py, you can run various commands from the terminal.

Building

python setup.py build

Installing

python setup.py install

Creating a Source Distribution

python setup.py sdist

Migration

Since distutils is removed in Python 3.12, users should migrate to setuptools. The usage is largely compatible.

programming/python/python