Search code examples
pythonpython-3.xcommand-linepipfailed-installation

Accidentally cancelled python's "pip" upgrade in the middle of the operation now pip is malfunctioning


I was trying to update python's pip command through the command line and accidentally pressed ctrl+c which cancelled the upgrade mid-process.

As soon as I realised what had happened I tried to rerun the command python -m install --upgrade pip and I got this error code:

(Currently running python 3.8.3) on Windows 10 Home

      File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 194, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\site-packages\pip\__main__.py", line 29, in <module>
        from pip._internal.cli.main import main as _main
      File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\site-packages\pip\_internal\cli\main.py", line 9, in <module>
        from pip._internal.cli.autocompletion import autocomplete
      File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\site-packages\pip\_internal\cli\autocompletion.py", line 10, in <module>
        from pip._internal.cli.main_parser import create_main_parser
      File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\site-packages\pip\_internal\cli\main_parser.py", line 8, in <module>
        from pip._internal.cli import cmdoptions
      File "C:\Users\HP\AppData\Local\Programs\Python\Python38\lib\site-packages\pip\_internal\cli\cmdoptions.py", line 21, in <module>
        from pip._vendor.packaging.utils import canonicalize_name
    ModuleNotFoundError: No module named 'pip._vendor'

Is there any way to fix this or should I reinstall python? I had no extra pip libraries installed except the requests library.


Solution

  • You can follow this guide. I also describe the steps here:

    1. Find where your python is located. In Windows it might be located in a path similar to C:\Users\<your-name>\AppsData\Local\Programs\Python\Python38-<minor-version>
    2. Download the get-pip.py script to the directory where your Python is located. You can just copy the content and paste it into a file with the same name
    3. Open the terminal (or PowerShell) and change the directory to where your Python is located.
    4. run the script as follows: python get-pip.py
    5. Verify the installation by executing: pip -V