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.
However, I can't find clear documentation about how to do this properly. 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 was I able to figure it out myself from the source code.
Specifically, 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 theplatform
module
How exactly does substituting setuptools
work? For example, should code like import distutils.command
be replaced with import setuptools.command
? Meanwhile, what should I do about uses of distutils.core.setup
and distutils.core.Extension
, which aren't listed here?
Furthermore: setuptools
does not appear under the modules or index list in the standard documentation, but I do see it in my Lib/site-packages
folder. Is it actually part of the standard distribution?
If not, how exactly should setuptools
be installed and used? Is it expected to become part of the standard distribution? Are clients expected to install it via Pip before they can run a setup.py script that imports setuptools
? Or is the idea that people shouldn't be running setup.py anymore at all?
This question addresses the problem from the perspective of developing a library. For installing a library, see Why did I get an error ModuleNotFoundError: No module named 'distutils'?.
ensurepip
package. setuptools itself is not stdlib. This is a configure option, so you may find in some cases that setuptools is not there. – Bestialitydistutils
withsetuptools
, on the level of code examples, and explanations of how to use the other standard library modules in the cases described in the migration guide. I'm capable of doing these things, but I don't write answers for Stack Overflow any more, and I feel that the Q&A would be more generally useful with that level of detail available. – Frisbydistutils
module. – Zaremski