From 0ac0fb3fe4185f74a40f54547081b736690cb2b8 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Sat, 9 May 2020 08:34:18 -0700 Subject: [PATCH] Fix when pip is invoked as python /path/to/pip/ Because pip ships with an __main__.py file, one valid way to invoke it is: python /usr/lib/python3.6/site-packages/pip/. This results in __package__ being the empty string This, in turn, triggers the code to add the pip wheel to sys.path. Unfortunately, while this is fine to do when it's restricted to a wheel just containing pip, it isn't okay to do when it is site-packages as that will mean that other things in site-packages could end up overriding things in the stdlib (*cough*enum34*cough*). Check file extension to limit when we end up adding the extra path to sys.path. Fixes #8214 --- news/8214.bugfix | 1 + src/pip/__main__.py | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 news/8214.bugfix diff --git a/news/8214.bugfix b/news/8214.bugfix new file mode 100644 index 00000000000..1dc5cd79d11 --- /dev/null +++ b/news/8214.bugfix @@ -0,0 +1 @@ +Fix installing packages which have a pyproject.toml when enum34 is installed. diff --git a/src/pip/__main__.py b/src/pip/__main__.py index 7c2505fa5bd..a529758b395 100644 --- a/src/pip/__main__.py +++ b/src/pip/__main__.py @@ -18,7 +18,10 @@ # Resulting path is the name of the wheel itself # Add that to sys.path so we can import pip path = os.path.dirname(os.path.dirname(__file__)) - sys.path.insert(0, path) + # __package__ could have also been the empty string if pip was invoked + # with the path to the pip directory. ie: as python /path/to/pip/. + if path.endswith('.whl'): + sys.path.insert(0, path) from pip._internal.cli.main import main as _main # isort:skip # noqa