[pip3] ImportError occurs

An error occurs when executing the pip3 command.

ImportError: cannot import name 'pkg_resources' from 'pip._vendor'

Cause

The pkg_resources is not in the pip._vendor package

When I checked with the CLI to see if the package actually existed, I found that it existed. Then, when I checked the location of the file, it turned out that it did not exist in the directory managed by pip.

--Check the existence of the file

Python 3.7.7 (default, Mar 10 2020, 15:43:33) 
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkg_resources
>>> pkg_resources.__file__
'/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py'
>>> 

--Package directory required to start pip /Users/username/Library/Python/3.7/lib/python/site-packages/pip/_vendor/

solution

--Copy the package file to a directory managed by pip --Create a symbolic link for the package file in a pip-managed directory

This time, we will deal with the idea of creating a symbolic link. ln -s /usr/local/lib/python3.7/site-packages/pkg_resources /Users/username/Library/Python/3.7/lib/python/site-packages/pip/_vendor/pkg_resources

% pip3

Usage:   
  pip3 <command> [options]
.
.
.

You can now do it happily.

Reference (actual error log)

Traceback (most recent call last):
  File "/Library/Developer/CommandLineTools/usr/bin/pip3", line 10, in <module>
    sys.exit(main())
  File "/Users/username/Library/Python/3.7/lib/python/site-packages/pip/_internal/__init__.py", line 16, in main
    from pip._internal.utils.entrypoints import _wrapper
  File "/Users/username/Library/Python/3.7/lib/python/site-packages/pip/_internal/utils/entrypoints.py", line 3, in <module>
    from pip._internal.cli.main import main
  File "/Users/username/Library/Python/3.7/lib/python/site-packages/pip/_internal/cli/main.py", line 10, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "/Users/username/Library/Python/3.7/lib/python/site-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "/Users/username/Library/Python/3.7/lib/python/site-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
    from pip._internal.cli import cmdoptions
  File "/Users/username/Library/Python/3.7/lib/python/site-packages/pip/_internal/cli/cmdoptions.py", line 28, in <module>
    from pip._internal.models.target_python import TargetPython
  File "/Users/username/Library/Python/3.7/lib/python/site-packages/pip/_internal/models/target_python.py", line 4, in <module>
    from pip._internal.utils.misc import normalize_version_info
  File "/Users/username/Library/Python/3.7/lib/python/site-packages/pip/_internal/utils/misc.py", line 20, in <module>
    from pip._vendor import pkg_resources
ImportError: cannot import name 'pkg_resources' from 'pip._vendor' 

Recommended Posts

[pip3] ImportError occurs
pip installation
1. Reinstall pip
pip memorandum
About pip
pip installation
pip installation