My_FAQ_什么是FAQ

(24) 2024-05-31 12:01:01

文章目录

    • cannot import name 'PackageFinder' from 'pip._internal.index'
      • Error message
      • Resolution
        • Remove the old file named "get-pip.py" first if you'v got one before
        • Get `get-pip` file by curl
        • Install pip
        • Check pip version
        • Run pip for a test

cannot import name ‘PackageFinder’ from ‘pip._internal.index’

Error message

gavin@GavindeMacBook-Pro ~ % pip3 --version       
Traceback (most recent call last):
File "/Library/Developer/CommandLineTools/usr/bin/pip3", line 6, in <module>
    from pip._internal import main
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages/pip/_internal/__init__.py", line 40, in <module>
    from pip._internal.cli.autocompletion import autocomplete
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages/pip/_internal/cli/autocompletion.py", line 8, in <module>
    from pip._internal.cli.main_parser import create_main_parser
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages/pip/_internal/cli/main_parser.py", line 11, in <module>
    from pip._internal.commands import (
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages/pip/_internal/commands/__init__.py", line 6, in <module>
    from pip._internal.commands.completion import CompletionCommand
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages/pip/_internal/commands/completion.py", line 6, in <module>
    from pip._internal.cli.base_command import Command
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/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' (/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages/pip/_internal/index/__init__.py)

Resolution

Remove the old file named “get-pip.py” first if you’v got one before
gavin@GavindeMacBook-Pro ~ % ls
Desktop				Downloads			Library				Movies				Pictures			PycharmProjects			Zhumu Cloud Meetings.zip
Documents			IdeaProjects			Mac快捷键大全.mht		Music				Public				Users				get-pip.py
gavin@GavindeMacBook-Pro ~ % rm get-pip.py 

gavin@GavindeMacBook-Pro ~ % ls
Desktop Downloads Library Movies Pictures PycharmProjects Zhumu Cloud Meetings.zip
Documents IdeaProjects Mac快捷键大全.mht Music Public Users

Get get-pip file by curl
gavin@GavindeMacBook-Pro ~ % curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py                                                                       
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                Dload  Upload   Total   Spent    Left  Speed
100 2108k  100 2108k    0     0   251k      0  0:00:08  0:00:08 --:--:--  340k
gavin@GavindeMacBook-Pro ~ % 
gavin@GavindeMacBook-Pro ~ % ls
Desktop				Downloads			Library				Movies				Pictures			PycharmProjects			Zhumu Cloud Meetings.zip
Documents			IdeaProjects			Mac快捷键大全.mht		Music				Public				Users				get-pip.py
Install pip
gavin@GavindeMacBook-Pro ~ % python3 get-pip.py                                                                       
Defaulting to user installation because normal site-packages is not writeable
Collecting pip
Using cached pip-21.3.1-py3-none-any.whl (1.7 MB)
Installing collected packages: pip
WARNING: The scripts pip, pip3 and pip3.8 are installed in '/Users/gavin/Library/Python/3.8/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-21.3.1
WARNING: You are using pip version 20.2.3; however, version 21.3.1 is available.
You should consider upgrading via the '/Library/Developer/CommandLineTools/usr/bin/python3 -m pip install --upgrade pip' command.
gavin@GavindeMacBook-Pro ~ % 
Check pip version

In this sample, I was suggested to update the version of pip.Maybe you do not need to do so.

gavin@GavindeMacBook-Pro ~ % pip3 --version
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
pip 21.3.1 from /Users/gavin/Library/Python/3.8/lib/python/site-packages/pip (python 3.8)
gavin@GavindeMacBook-Pro ~ % /Library/Developer/CommandLineTools/usr/bin/python3 -m pip install --upgrade pip
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pip in ./Library/Python/3.8/lib/python/site-packages (21.3.1)
gavin@GavindeMacBook-Pro ~ %    
Run pip for a test
gavin@GavindeMacBook-Pro ~ % pip install pycrypto
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Defaulting to user installation because normal site-packages is not writeable
Collecting pycrypto
Downloading pycrypto-2.6.1.tar.gz (446 kB)
    |████████████████████████████████| 446 kB 10 kB/s 
Building wheels for collected packages: pycrypto
Building wheel for pycrypto (setup.py) ... done
Created wheel for pycrypto: filename=pycrypto-2.6.1-cp27-cp27m-macosx_11_4_x86_64.whl size=463938 sha256=d05ea0cae5a3cb3fb6d0cb045e3a59fffaf8510162349374d1ec48bf2bb6f648
Stored in directory: /Users/gavin/Library/Caches/pip/wheels/b6/e6/c8/d1eca13628952ceec1d40d96e0a7a1380460d2349ce0b85312
Successfully built pycrypto
Installing collected packages: pycrypto
Successfully installed pycrypto-2.6.1
gavin@GavindeMacBook-Pro ~ % 
THE END

发表回复