Pip: cannot import name 'PackageFinder'

Created on 18 May 2020  路  11Comments  路  Source: pypa/pip

  • pip version: Not sure / Possibly: 19.2.3 (it says so in __init__ in the pip directory)
  • Python version: 3.8.3
  • Operating system: Win 10

After updating python (previous 8.3.1; first version installed on this computer), pip doesn't work at all. This is an example error, similar to those when I try to use pip for something:

_C:\Users\ibm>pip
Traceback (most recent call last):
  File "c:\users\ibm\appdata\local\programs\python\python38-32\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\ibm\appdata\local\programs\python\python38-32\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\ibm\AppData\Local\Programs\Python\Python38-32\Scripts\pip.exe\__main__.py", line 5, in <module>
  File "c:\users\ibm\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\__init__.py", line 40, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "c:\users\ibm\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\cli\autocompletion.py", line 8, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "c:\users\ibm\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\cli\main_parser.py", line 11, in <module>
    from pip._internal.commands import (
  File "c:\users\ibm\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\commands\__init__.py", line 6, in <module>
    from pip._internal.commands.completion import CompletionCommand
  File "c:\users\ibm\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\commands\completion.py", line 6, in <module>
    from pip._internal.cli.base_command import Command
  File "c:\users\ibm\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\cli\base_command.py", line 26, in <module>
    from pip._internal.index import PackageFinder
ImportError: cannot import name 'PackageFinder' from 'pip._internal.index' (c:\users\ibm\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\index\__init__.py)_

So: I'm not sure what to do and there seems to be no solution somewhere online...

auto-locked

All 11 comments

Hi, thanks for reporting. Have you tried if the behavior persists with the latest pip (20.1)? Also it'd be nice if you can reformat the log within triple ticks, i.e.

```
log here
```

Well... the usual using pip to update itself (that is how it works usually?) doesn't works so im not sure how to get to 20.1 pip.

Also I reformatted the log and thank you for fast reply...

Can you try python -m pip install -U pip as noted in https://pip.pypa.io/en/stable/installing/#upgrading-pip

That produces a similar (if not same error):

C:\Users\ibm>python -m pip install -U pip
Traceback (most recent call last):
  File "C:\Users\ibm\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\ibm\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\ibm\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pip\__main__.py", line 16, in <module>
    from pip._internal import main as _main  # isort:skip # noqa
  File "C:\Users\ibm\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pip\_internal\__init__.py", line 40, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "C:\Users\ibm\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pip\_internal\cli\autocompletion.py", line 8, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "C:\Users\ibm\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pip\_internal\cli\main_parser.py", line 11, in <module>
    from pip._internal.commands import (
  File "C:\Users\ibm\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pip\_internal\commands\__init__.py", line 6, in <module>
    from pip._internal.commands.completion import CompletionCommand
  File "C:\Users\ibm\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pip\_internal\commands\completion.py", line 6, in <module>
    from pip._internal.cli.base_command import Command
  File "C:\Users\ibm\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pip\_internal\cli\base_command.py", line 26, in <module>
    from pip._internal.index import PackageFinder
ImportError: cannot import name 'PackageFinder' from 'pip._internal.index' (C:\Users\ibm\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pip\_internal\index\__init__.py)

Could you also correct your python version (8.3.8 and 8.3.1) don't look correct to me.

It will also help to verify if your pip is pointing to the upgraded python version. (From the logs it seems to be pointing to Python38-32, which I assume is python 3.8.3) ?

pip 19.2.3 has _internal.index.PackageFinder, while in higher version index is refactored from a module into a package and no longer has the class at the top level. For this reason, I suspect that for some reason @iNeedUsernameHere is having a broken pip's install. Perse could try to uninstall pip and use get-pip.py to get a new one. However, I'm still really curious to learn about the cause of this problem.

One scenario for this (on Windows) is a botched uninstallation by pip. If the uninstallation fails half-way, a subsequence py -m pip install -U pip may think the previous version of pip does not need to be uninstalled, leaving stray .pyc files behind that lead to incorrect imports.

python 3.8.3 of course... (sadly I'm not a time traveller with python 8...)

Okay so 1.) I found a solution and 2.) here is a complete runthrough of my findings/the procedure:

  1. Unistalling python (and python launcher) using standard windows method (picA)
    -this uninstall left some files (pic B1 and B2) for both python and pip

  2. Delete those files shown in picB1 and picB2 (You might have to search your drive or enter the path (C:\Users\ibm\AppData\Local\Programs\Python; C:\Users\ibm\AppData\Localpip; Use your username instead of "ibm") as Windows doesn't seem to display it through explorer directly

  3. Shouldn't be neccessary: I removed python from Path (both mentions; picC)

  4. Normal install of python (not forgetting add Python to PATH option; picD)

  5. Pip is working! (But in an old 19.2.3 version which seems to be the standard included for python 3.8.3 download)(picF)

  6. Update pip using the standard command (picG)

Summary of I think went wrong initially:
Unistalling Python to install newer version left some (older) files for pip and/or python. Then, when reinstalling a newer version, the installing tool didn't replace these files or alternatively didn't install some needed new files, as the directory or so was allready there (I have no clue how it works so this is basically a slightly educated guess). Later, when trying to run pip, it needed some file that wasn't there, not working and producing the error.

PicA:
picA
PicB1:
picB1
PicB2:
picB2
PicC: (This is: Control Panel - (System and Security) - System - Advanced System Settings Environmental Variables - Path)
picC
PicD:
picD
PicF:
picF
PicG:
picG

And my computer is german, so some translations:
1) Dieser PC - Lokaler Datentr盲ger(C:) - Benutzer - ... translates to something like this:
_This Computer - Lokal Drive (C:) - User - ..._
2) For picC it I allready mentioned it where the picture is
3)That should be it

That's great that you were able to resolve the issue. I think you can go ahead and close this issue now 馃槉

Okay, thanks for the quick answers everyone (especially McSinycx and uranusjr, who brought me to the idea of manually searching and removing files)!
Hope this can help someone...

Was this page helpful?
0 / 5 - 0 ratings