Hello.
In Fedora, our pip package Recommends setuptools. Practically that means:
- Majority of users who install pip will get setuptools by default.
- Users can explicitly uninstall setuptools after installing pip or exclude setuptools when installing pip.
- Users might op-out from installing Recommended packages by default to save space (I suppose the majority of such users do it in containers or a similar environment), and such users won’t get setuptools with pip.
I like that our users have a choice not to install setuptools with pip. I also like that by default, they’ll get it. What worries me is the experience for users from (3) who might get pip without setuptools while not explicitly asking for this setup. When pip attempts to install a package from sdist without a PEP 517/518 build backend specified, it’ll fail with:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'setuptools'
This traceback is displayed multiple times, as backtracking causes lots of failed attempts.
Originally, I thought: Right, it’s because the setup.py
script imports it, but I’ve realized it is actually pip that does that:
Even packages that don’t use setuptools in their setup.py
script will fail with the same problem. I’ve successfully tested the assumption with this example:
from distutils.core import setup
setup()
After the recent discussions on the Python-Dev mailing list – Mailman 3 Does ensurepip still have to include a copy of setuptools? - Python-Dev - python.org, and after the recent discussion with @jaraco in Declare dependencies in metadata by jaraco · Pull Request #2764 · pypa/setuptools · GitHub, I have mixed expectations whether pip should always Require (rather than Recommend) setuptools. In the RPM world, that means:
- All users who install pip will get setuptools by default.
- Users cannot explicitly uninstall setuptools after installing pip nor exclude setuptools when installing pip.
- Users might op-out from installing Recommended packages by default to save space, and such users will still get setuptools with pip.
This feels like a quite inflexible setup. I would rather allow not installing setuptools with pip when users know what they are doing, but users from (3) might not understand this problem, as it might not be from their domain at all. The Traceback might be interpreted as a problem in pip.
Would it make sense to handle missing setuptools from pip’s code in a more explicit way? Ideas:
- Instead of displaying a Traceback, display an error message explaining that setuptools is not installed and installing <package> requires it. Suggest installing setuptools before installing <package> or using
--use-pep517
to install <package>. - Default to
--use-pep517
when setuptools is not installed (see also Default to --use-pep517 · Issue #9175 · pypa/pip · GitHub).
Pip already handles the presence or absence of wheel differently, so there is a precedent.
What do you think?
CC’ing also @pradyunsg and @encukou who might be interested in this topic.