Correct the version Conflict of pip and execute the library installation normally.

image.png

"Why does Python package management die soon?"

environment

--The environment that occurred this time is as follows, Pipfile has already been created

$ python -V
Python 3.7.6

What happened

--Library installation around pip install or pipenv install doesn't work --Even if you look at the version of pip, the following error was thrown

$ pip -V
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 583, in _build_master
    ws.require(__requires__)
  File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 900, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 791, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.VersionConflict: (pip 20.1 (/usr/local/lib/python3.7/site-packages), Requirement.parse('pip==19.3.1'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/opt/python/libexec/bin/pip", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 3251, in <module>
    @_call_aside
  File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 3235, in _call_aside
    f(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 3264, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 585, in _build_master
    return cls._build_from_requirements(__requires__)
  File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 598, in _build_from_requirements
    dists = ws.resolve(reqs, Environment())
  File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 786, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'pip==19.3.1' distribution was not found and is required by the application

Cause

――It looks like this, the version of pip seems to be in conflict --Because the requested pip is 19.3.1 and the running pip is 20.1 --The theory that was upgraded somewhere (because it's Warning ...)

pkg_resources.VersionConflict: (pip 20.1 (/usr/local/lib/python3.7/site-packages), Requirement.parse('pip==19.3.1'))

Countermeasures

--Install the required version of pip (this time 19.3.1) --The installation method was described in PyPA official documentation --This method is also useful if your local environment Python and pip are not tied together.

# python get-pip.Get the file to run py with curl
$ 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 1824k  100 1824k    0     0  1650k      0  0:00:01  0:00:01 --:--:-- 1650k

#Install pip by specifying the version of pip as an argument
$ python get-pip.py pip==19.3.1
Looking in indexes: https://pypi.python.org/simple/
Collecting pip==19.3.1
  Downloading pip-19.3.1-py2.py3-none-any.whl (1.4 MB)
     |████████████████████████████████| 1.4 MB 553 kB/s
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 20.1
    Uninstalling pip-20.1:
      Successfully uninstalled pip-20.1
Successfully installed pip-19.3.1

result

--The specified version of pip has been downloaded in conjunction with your local Python ――After that, please do pip install or pipenv install as you like.

$ pip -V                                                                                                                                       
pip 19.3.1 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

Recommended Posts

Correct the version Conflict of pip and execute the library installation normally.
Installation method using the pip command of the Python package (library) Mac environment
Installation of OpenMDAO (version 1.7.1)
Check the type and version of your Linux distribution
I want to know the features of Python and pip
Commands and files to check the version of CentOS Linux
[Package management] Installation destination and internal processing of apt and pip
Align the version of chromedriver_binary
Source installation and installation of Python
Test the version of the argparse module
The story of Python and the story of NaN
Installation of SciPy and matplotlib (Python)
Is the probability of precipitation correct?
pyenv-change the python version of virtualenv
Change the Python version of Homebrew
Installation and easy usage of pytest
The case that the installation of pip became easier before I knew it