29

According to PEP 632, distutils will be formally marked as deprecated, and in Python 3.12, it will be removed. My product is soon going to support Python 3.10 and I don't want to put up with deprecation warnings, so I would like to remove references to distutils now. The problem is that I can't find good, comprehensive documentation that systematically lets me know that A in distutils can be replaced by B in modules C, D, and E. The Migration Advice in the PEP is surprisingly sketchy, and I haven't found standard documentation for distutils, or for whatever modules (such as setuptools?) that are required to replace distutils, that would let me fill in the gaps. Nor am I sure how to look at the content of the installed standard distribution (that is, the physical directories and files) in order to answer these questions for myself.

The "Migration Advice" section says:

For these modules or types, setuptools is the best substitute:

  • distutils.ccompiler
  • distutils.cmd.Command
  • distutils.command
  • distutils.config
  • distutils.core.Distribution
  • distutils.errors

...

For these modules or functions, use the standard library module shown:

...

  • distutils.util.get_platform — use the platform module

Presumably, that means that setuptools has either a drop-in replacement or something close to it for these modules or types (though I'm not sure how to verify that). So, for instance, perhaps setuptools.command.build_py can replace distutils.command.build_py. Is that correct? In any case, what about these?

  • distutils.core.setup
  • distutils.core.Extension

Furthermore, what am I supposed to make of the fact that setuptools does not appear under the modules or index list in the standard documentation? It is part of the standard distribution, right? I do see it under Lib/site-packages.

UPDATE 1: If setuptools is not currently part of the standard distribution, is it expected to become one, say, in Python 3.11 or 3.12? Are customers expected to install it (via pip?) before they can run a setup.py script that imports setuptools? Or is the thought that people shouldn't be running setup.py anymore at all?

Knowing how to replace distutils.core.setup and distutils.core.Extension is probably enough for my current needs, but answers to the other questions I've asked would be quite helpful.

UPDATE 2:

setuptools is indeed part of the python.org standard distribution, as can be determined by importing it from a freshly installed Python interpreter from python.org. The thing that was confusing me was that it is documented on a separate site, with a separate style, from python.org. However, as SuperStormer pointed out in the comments, some Linux distributions, such as Debian, don't install it by default when you install Python.

UPDATE 3:

This command:

Python-3.9.1/python -m ensurepip --default-pip 

installs both pip and setuptools on Debian 10 on a Python installation freshly downloaded and built from python.org. Before the command is executed, pip is absent and setuptools cannot be imported.

Alan
  • 1,889
  • 2
  • 18
  • 30
  • What happened when you tried to use setuptools? – mkrieger1 Nov 05 '21 at 20:37
  • 4
    setuptools **is not** part of the stdlib, it is instead a separate package on PyPI. – SuperStormer Nov 05 '21 at 20:39
  • 4
    distutils.core.setup should be replaced by setuptools.setup. For extensions, see https://setuptools.pypa.io/en/latest/userguide/extension.html – SuperStormer Nov 05 '21 at 20:41
  • @SuperStormer, whether or not setuptools is part of the "stdlib" (and I'm not sure what you mean by that term), and whether or not it's produced by the same people who produce core Python, it is what I would call part of the standard distribution, since the module can be imported by a freshly downloaded Python interpreter with no auxiliary modules installed. I updated my post to indicate that. – Alan Nov 29 '21 at 19:28
  • 2
    "since the module can be imported by a freshly downloaded Python interpreter with no auxiliary modules installed" Nope, setuptools is only bundled with Python for certain installations (python.org being one of them). For instance, some linux distros (ie. Debian, Alpine) don't install it by default when you install `python3`. – SuperStormer Nov 29 '21 at 21:52
  • stdlib == standard library, for future reference – SuperStormer Nov 29 '21 at 21:54
  • 3
    setuptools is _vendored_ in CPython, along with pip, via the stdlib [`ensurepip`](https://docs.python.org/3/library/ensurepip.html) package. setuptools itself is not stdlib. This is a [configure](https://github.com/python/cpython/blob/a39f46afdead515e7ac3722464b5ee8d7b0b2c9b/configure#L20263-L20285) option, so you may find in some cases that setuptools is not there. – wim Dec 01 '21 at 00:57

1 Answers1

2
  • Yes setuptools can fully replace distutils for everything
  • distutils.core.setup maps to setuptools.setup
  • distutils.core.Extension maps to setuptools.Extension
  • setuptools is not part of the standard library (hence its absence from the doc) but it is part of the standard python.org distribution.
  • some distributions choose to separate setuptools and pip from the default python package because they don't assume you will be using python for writing code, however some system tools require python (apt among others). If you plan to use the distribution as a development tool, you are expected to install pip and setuptools from the distribution repositories.
WIP
  • 348
  • 2
  • 11