A Guide to the Distutils Module
For those not familiar with it, distutils is the original package management system for Python. It is included in the standard library, but has since been superseded by setuptools.
While you can still use distutils to create and distribute a package, it is no longer considered part of the Python ecosystem and may eventually be dropped by the core development team. As such, it is recommended to move to setuptools as soon as possible.
Setuptools is a set of tools for creating, installing and upgrading a Python software package. It is an alternative to the Distutils package management system and provides additional functionality, especially for working with python extensions.
This module defines a class called Distribution, which represents the distribution that will be built and installed. The Distribution constructor accepts various keyword arguments; see the documentation for a list of these arguments.
Unlike a command line argument, which is a simple string value, a Distribution has a complex structure and requires a special Python interpreter instance to process it. It is important that all the arguments are passed to the Distribution constructor correctly, or the build will fail.
There is one Distribution instance in a run of Distutils, but there may be many Command instances created: each of these is a Import distutils.core modulenotfounderror: no module named 'distutils' subclass of the Command class, and implements a single distutils command. These commands are called by the Distribution object when it needs help performing its job.
The most important command is install, which does the bulk of work when a distribution is being built. In particular, it installs files that will be used by the python_compile phase of the build (or in the case of a Python extension, the python_inplace phase).
It also installs any src directory tree into a new location dst, recursively copying files and their parent directories along the way. If dst is not a directory, it will be created with mkdir(); if the verbose flag is true, a one-line summary of each mkdir is printed to stdout.
Besides install, other notable commands are build_ext and update. build_ext builds a C extension and puts it alongside the Python source code in its directory, which can be useful for testing extensions.
update performs the same function as install, except it also updates the metadata that is used by the python_compile and python_inplace phases. The python_compile phase uses this information to determine which compiler and linker to use.
The other two functions are a little more obscure. generate_config inserts the environment variables that differ across systems into the python_compile Makefile, such as the compiler and linker options. Finally, get_version returns a version of a filename that has been escaped for inclusion in an RFC 822 header, using the standard string replacement functions. This is mostly needed for the python_inplace build of Python modules, and should not be used in general-purpose builds.