40

At work, we use Github actions to build and test our Pull Requests before they can be approved. On Friday afternoon, everything was working just fine. On Monday morning, all tests were failing pretty early, with an error showing that pip could no longer find its own exceptions. Did something change with the newest Pip?

As you can see in the errors below, our own code isn't referenced, and I'm fairly certain nothing in our flow changed between Friday and Monday (we're a small team and the approved PRs don't have anything surprising there).

Error Traceback:

Traceback (most recent call last):
    File "/opt/hostedtoolcache/Python/3.7.9/x64/bin/pip", line 5, in <module>
      from pip._internal.cli.main import main
    File "/opt/hostedtoolcache/Python/3.7.9/x64/lib/python3.7/site-packages/pip/_internal/cli/main.py", line 8, in <module>
      from pip._internal.cli.autocompletion import autocomplete
    File "/opt/hostedtoolcache/Python/3.7.9/x64/lib/python3.7/site-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
      from pip._internal.cli.main_parser import create_main_parser
    File "/opt/hostedtoolcache/Python/3.7.9/x64/lib/python3.7/site-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
      from pip._internal.cli import cmdoptions
    File "/opt/hostedtoolcache/Python/3.7.9/x64/lib/python3.7/site-packages/pip/_internal/cli/cmdoptions.py", line 22, in <module>
      from pip._internal.cli.progress_bars import BAR_TYPES
    File "/opt/hostedtoolcache/Python/3.7.9/x64/lib/python3.7/site-packages/pip/_internal/cli/progress_bars.py", line 9, in <module>
      from pip._internal.utils.logging import get_indentation
    File "/opt/hostedtoolcache/Python/3.7.9/x64/lib/python3.7/site-packages/pip/_internal/utils/logging.py", line 14, in <module>
      from pip._internal.utils.misc import ensure_dir
    File "/opt/hostedtoolcache/Python/3.7.9/x64/lib/python3.7/site-packages/pip/_internal/utils/misc.py", line 29, in <module>
      from pip._internal.locations import get_major_minor_version, site_packages, user_site
    File "/opt/hostedtoolcache/Python/3.7.9/x64/lib/python3.7/site-packages/pip/_internal/locations/__init__.py", line 9, in <module>
      from . import _distutils, _sysconfig
    File "/opt/hostedtoolcache/Python/3.7.9/x64/lib/python3.7/site-packages/pip/_internal/locations/_sysconfig.py", line 8, in <module>
      from pip._internal.exceptions import InvalidSchemeCombination, UserInstallationInvalid
  ImportError: cannot import name 'InvalidSchemeCombination' from 'pip._internal.exceptions' (/opt/hostedtoolcache/Python/3.7.9/x64/lib/python3.7/site-packages/pip/_internal/exceptions.py)
Error: The process '/opt/hostedtoolcache/Python/3.7.9/x64/bin/pip' failed with exit code 1
Peter Badida
  • 11,310
  • 10
  • 44
  • 90
Zach Milan
  • 421
  • 1
  • 4
  • 4
  • 1
    Workaround here: https://stackoverflow.com/questions/62074986/my-pip-is-broken-on-windows-how-can-i-fix-it/66332322#66332322 – Marc Sances Apr 26 '21 at 20:53

9 Answers9

30

For macOS X, this problem happened to me after I upgraded my homebrew, What really worked for me is this,

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

then

python get-pip.py

according to the discussion in the reference, it seems only pip version 21.1.1 fixed the problem.

Refer to the following discussion https://github.com/pypa/pip/issues/7217

Dr Neo
  • 724
  • 6
  • 11
  • 1
    I was facing the same issue. Thanks to your comment my pip is now running again! – postnubilaphoebus May 21 '21 at 09:49
  • 1
    When I do this from within a Conda environment, I get the following `Defaulting to user installation because normal site-packages is not writeable`. Do you know what could be the cause? In other environments this seems to work. – MadPhysicist Jun 07 '21 at 15:01
  • Sorry, I am not sure, but I am certain that it worked for me while my conda environment was activated. you can try: - How about running the command as a root user (sudo blah blah.) - Check `pip`, mine is /Users/my_name/opt/anaconda3/bin/pip similar to my python /Users/my_name/opt/anaconda3/bin/pip. using `which pip` - Deactivate conda environment and check your python version first, to run the commands above again. - How about re-install Anaconda again? I hope this is helpful, good luck. – Dr Neo Jun 07 '21 at 16:05
  • 1
    I had this problem while building an image with kaniko, but it doesn't happen with `docker build`. Reinstalling pip in my dockerfile fixed it. – MatrixManAtYrService Jun 14 '21 at 18:46
  • One-liner: `curl https://bootstrap.pypa.io/get-pip.py | python` – cambunctious Aug 15 '22 at 14:42
19

ImportError: cannot import name 'InvalidSchemeCombination' from 'pip._internal.exceptions'

The reason behind this error is that the pip file is corrupted.

The 100% solution is as simple as follows:

  1. First execute the command: python -m ensurepip --default-pip
  2. Download the get-pip.py script file from https://bootstrap.pypa.io/get-pip.py
  3. Open a terminal/command prompt (Admin privileges), cd to the folder containing the downloaded get-pip.py file and run: python get-pip.py
  4. The problem has now been resolved.
Mahmood G. B.
  • 195
  • 1
  • 5
9

Yes, there has been a release and the last commit modifying that file is from 2 days ago, however most likely it'll be something older.

Citing from the NEWS.rst it looks like there's some migration in progress:

Process
-------

- Start installation scheme migration from ``distutils`` to ``sysconfig``. A
  warning is implemented to detect differences between the two implementations to
  encourage user reports, so we can avoid breakages before they happen.

However, it'd be for the best to submit a bug so they can release a fix if necessary.

Classic workaround, downgrade to 21.0.1 i.e. the next latest version after 21.1:

pip install pip==21.0.1

Update:

Linking the issue #9880 submitted by OP.

Update 2:

Adjusting according to the OP's issue and another person's experience in the linked issue.

Don't use -I flag for pip install, it's for installing over the files (hence pip install --ignore-installed) you have present on your system instead of the real upgrading (installing a new version, then removing the old one).

Instead, use -U (i.e. pip install --upgrade) flag which will do what you want.

Peter Badida
  • 11,310
  • 10
  • 44
  • 90
  • 3
    Thanks Peter. I've submitted a bug even though I don't have the best repro details. – Zach Milan Apr 26 '21 at 21:02
  • 1
    That's mostly enough for the maintainers, you've provided a full traceback. Perhaps even the command you ran would be helpful to narrow down the flow e.g. perhaps it's just one specific package causing problems e.g. due to strange version/name/etc. – Peter Badida Apr 26 '21 at 21:06
  • 1
    Thank y'all! FWIW, seems like `pip install --ignore-installed pip=={thing}` may be weird, whereas `pip install pip=={thing}` is not. Added a comment to the issue: [link](https://github.com/pypa/pip/issues/9880#issuecomment-828074854) – Eric Cousineau Apr 28 '21 at 01:39
  • Update on `--ignore-installed`: should prolly avoid this: [link](https://github.com/pypa/pip/issues/9880#issuecomment-828102905) – Eric Cousineau Apr 28 '21 at 03:26
9

pip install pip==21.0.1 did not work for my case. Running this command still raise to the same error.

You need to save get-pip.py file in the anaconda3\Scripts directory or anaconda3\envs\[env_name]\Scripts if you are working on virtual environment. Then, you need to cd to this directory:

cd anaconda3\Scripts

After that run:

python get-pip.py pip==19.3.1

or

python get-pip.py pip==21.0.1
Maryam Bahrami
  • 1,056
  • 9
  • 18
  • My pip was completely broken, but this worked for me. To install the 2023 version, run this line in shell: `python get-pip.py pip==23.0.1` – mknull Mar 09 '23 at 15:49
  • You're a savior! This doesn't require admin rights (good for work computers), is quick and solves the corrupter pip – Pengshe Jun 05 '23 at 15:48
3

I was facing the same issue on linux. Here is the solution for debian or similar versions:

First download the get-pip.py with:

wget https://bootstrap.pypa.io/get-pip.py

Or go to the url and copy all the contents to a new .py file on your system. You can name it whatever you but make sure to use same file name in the next step.

And then install a specific version of pip (execute in the same directory as the get-pip.py file):

python get-pip.py pip==21.0.1 #or any other version
2

pip command was not working at all

For windows 10 this worked for me :-

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

after this

python get-pip.py
Avijit
  • 23
  • 3
2

This issue was encountered after updating Conda via conda update anaconda

Issue seems to be related to pip v21.2.4

As Mahmood G. B. indicated above:

  1. Execute the command: python -m ensurepip --default-pip
  2. Go to https://bootstrap.pypa.io/
  3. Right click on get-pip.py then save file to local directory
  4. Open a terminal/command prompt (Admin privileges), cd to the folder containing the downloaded get-pip.py file and run: python get-pip.py
  5. After installation ignore prompt to upgrade

"WARNING: You are using pip version 21.0; however, version 21.3.1 is available. You should consider upgrading via the python -m pip install --upgrade pip command"

notilas
  • 2,323
  • 4
  • 23
  • 36
1

For Windows users, this problem happened to me after I upgraded to pip v21.2.4, What really worked for me is this,

So, I deleted my older v of pip, and reinstall using CMD Go through these steps to delete those older versions :

  1. On the desktop, click or tap the File Explorer button on the taskbar.
  2. Type this path in search bar C:\Users\Win\anaconda3\Scripts or old installation of python38 some way you can apply
  3. Look for the file where the name is pip3,pip3.8,pip3-script or pip-script delete those files.
  4. after deletion of those files reinstall pip using cmd its works fine.
dbc
  • 104,963
  • 20
  • 228
  • 340
-3
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py

python get-pip.py
DimiDak
  • 4,820
  • 2
  • 26
  • 32
  • 1
    This looks a lot like the top answer. Can you explain why the extra `2.7` should be used? – General Grievance Jan 21 '22 at 05:18
  • @Calculuswhiz If you 'll use the top answer you 'll understand why.. – DimiDak Jan 21 '22 at 08:52
  • This isn't a question I had. The only reason I ask is that this answer came up in the Low Quality Answers review queue, likely because it was code-only with no explanation. With 9 other answers here, it would be better to explain why it's correct. – General Grievance Jan 21 '22 at 13:33