Reputation: 235
I think my pip is broken. I've tried everything from doing force reinstall to update everything but nothing seems to work.
when I do pip2 -v
then I get the following:
Traceback (most recent call last):
File "/usr/local/bin/pip2", line 6, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3144, in <module>
@_call_aside
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3128, in _call_aside
f(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3157, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 666, in _build_master
ws.require(__requires__)
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 984, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 870, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'pip==9.0.1' distribution was not found and is required by the application
when I do pip -v
then I get the following:
Traceback (most recent call last):
File "/bin/pip", line 7, in <module>
from pip._internal import main
ImportError: No module named pip._internal
FYI: I'm on Mac OSX
and am using Python 2.7.14
Please help!!
Upvotes: 8
Views: 20263
Reputation: 99
As for me. I hava several python version in my OS.
When i run pip2 -v
, it shows
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/pkg_resources/__init__.py", line 567, in _build_master
ws.require(__requires__)
File "/usr/local/lib/python3.5/dist-packages/pkg_resources/__init__.py", line 884, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/local/lib/python3.5/dist-packages/pkg_resources/__init__.py", line 775, in resolve
raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.VersionConflict: (pip 20.3.4 (/usr/local/lib/python3.5/dist-packages), Requirement.parse('pip==8.1.1'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/bin/pip2", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python3.5/dist-packages/pkg_resources/__init__.py", line 3238, in <module>
@_call_aside
File "/usr/local/lib/python3.5/dist-packages/pkg_resources/__init__.py", line 3222, in _call_aside
f(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/pkg_resources/__init__.py", line 3251, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/local/lib/python3.5/dist-packages/pkg_resources/__init__.py", line 569, in _build_master
return cls._build_from_requirements(__requires__)
File "/usr/local/lib/python3.5/dist-packages/pkg_resources/__init__.py", line 582, in _build_from_requirements
dists = ws.resolve(reqs, Environment())
File "/usr/local/lib/python3.5/dist-packages/pkg_resources/__init__.py", line 770, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'pip==8.1.1' distribution was not found and is required by the application
It shows that it find pip version in python3.5
directroy, so I think it maybe the multi version problem.
So i execute ls -l /usr/bin/ |grep python
, it shows that
lrwxrwxrwx 1 root root 26 Aug 16 2019 dh_pypy -> ../share/dh-python/dh_pypy
-rwxr-xr-x 1 root root 1056 Nov 24 2017 dh_python2
lrwxrwxrwx 1 root root 29 Aug 16 2019 dh_python3 -> ../share/dh-python/dh_python3
lrwxrwxrwx 1 root root 23 Mar 2 2021 pdb2.7 -> ../lib/python2.7/pdb.py
lrwxrwxrwx 1 root root 23 Jan 27 2021 pdb3.5 -> ../lib/python3.5/pdb.py
lrwxrwxrwx 1 root root 31 Oct 25 2021 py3versions -> ../share/python3/py3versions.py
lrwxrwxrwx 1 root root 26 Aug 16 2019 pybuild -> ../share/dh-python/pybuild
lrwxrwxrwx 1 root root 24 Aug 11 07:16 python -> /etc/alternatives/python
lrwxrwxrwx 1 root root 9 Nov 24 2017 python2 -> python2.7
-rwxr-xr-x 1 root root 3492624 Mar 2 2021 python2.7
lrwxrwxrwx 1 root root 33 Mar 2 2021 python2.7-config -> x86_64-linux-gnu-python2.7-config
lrwxrwxrwx 1 root root 16 Nov 24 2017 python2-config -> python2.7-config
lrwxrwxrwx 1 root root 9 Oct 25 2021 python3 -> python3.5
-rwxr-xr-x 2 root root 4456208 Jan 27 2021 python3.5
lrwxrwxrwx 1 root root 33 Jan 27 2021 python3.5-config -> x86_64-linux-gnu-python3.5-config
-rwxr-xr-x 2 root root 4456208 Jan 27 2021 python3.5m
lrwxrwxrwx 1 root root 34 Jan 27 2021 python3.5m-config -> x86_64-linux-gnu-python3.5m-config
lrwxrwxrwx 1 root root 16 Mar 23 2016 python3-config -> python3.5-config
lrwxrwxrwx 1 root root 10 Oct 25 2021 python3m -> python3.5m
lrwxrwxrwx 1 root root 17 Mar 23 2016 python3m-config -> python3.5m-config
lrwxrwxrwx 1 root root 16 Nov 24 2017 python-config -> python2.7-config
lrwxrwxrwx 1 root root 29 Nov 24 2017 pyversions -> ../share/python/pyversions.py
-rwxr-xr-x 1 root root 2909 Mar 2 2021 x86_64-linux-gnu-python2.7-config
lrwxrwxrwx 1 root root 34 Jan 27 2021 x86_64-linux-gnu-python3.5-config -> x86_64-linux-gnu-python3.5m-config
-rwxr-xr-x 1 root root 3185 Jan 27 2021 x86_64-linux-gnu-python3.5m-config
lrwxrwxrwx 1 root root 33 Mar 23 2016 x86_64-linux-gnu-python3-config -> x86_64-linux-gnu-python3.5-config
lrwxrwxrwx 1 root root 34 Mar 23 2016 x86_64-linux-gnu-python3m-config -> x86_64-linux-gnu-python3.5m-config
lrwxrwxrwx 1 root root 33 Nov 24 2017 x86_64-linux-gnu-python-config -> x86_64-linux-gnu-python2.7-config
In my case, I want my pip2 work well, so I need make /usr/bin/python
is python2.
so I do sudo mv /usr/bin/python /usr/bin/python_bak
and sudo cp /usr/bin/python2 /usr/bin/python
Then pip2 works well.
Don't forget mv python_bak python
to recover.
Sorry for my poor english.
Upvotes: 1
Reputation: 1214
Just hit this same problem on my mac and I fixed it by
$ brew upgrade python@2
The above command, essentially, gives Apple's python 2.7.10 back to you.
$ which python
/usr/bin/python
$ python -V
Python 2.7.10
Pip worked immediately and can be upgraded to 19.0.1
pip --version
pip 18.1 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)
pip install --upgrade pip setuptools
pip --version
pip 19.0.1 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)
And here is what brew upgrade python@2
has to say about python on mac
==> python@2
Pip and setuptools have been installed. To update them
pip install --upgrade pip setuptools
You can install Python packages with
pip install <package>
They will install into the site-package directory
/usr/local/lib/python2.7/site-packages
See: https://docs.brew.sh/Homebrew-and-Python
Upvotes: 2
Reputation: 365915
Since you're on macOS, your computer already had a Python 2.7, pre-installed by Apple. If you're on macOS 10.13, it's 2.7.10; older versions of course have older versions.
Meanwhile, you've installed Python 2.7.14. You didn't tell us how—python.org installer, Anaconda, Homebrew, whatever—but that's fine.
The problem is that the Apple Python 2.7.10 is still your "primary" 2.7, so you somehow ended up with a pip
9.0.1 that installed its packages for your 2.7.14, but thinks it's supposed to run with the Apple 2.7.10 instead. That's why it's looking in /usr/local/lib/python2.7/site-packages
, which is the site-packages for Apple's 2.7.10, not for your 2.7.14. And you either don't have pip
for the Apple 2.7.10, or have an older version. Hence the error.
Headaches in dealing with multiple Python installations—especially multiple installations of the same version—are why the Python Packaging User Guide suggests that you:
python -m pip
to run pip
.I don't know how you normally make sure you're running your 2.7.14 instead of Apple's 2.7.10, but whatever command you run, if you do the same thing with a -m pip
, it's guaranteed to use your 2.7.14 rather than Apple's 2.7.10. For example, if you normally type python2
, use python2 -m pip
instead of pip2
.
Meanwhile, if you activate a virtual environment, both python
and pip
(and other things like 2to3
) are going to be the versions that go with that environment, no matter what else you happen to have installed and how confusing your overall system setup is.
Upvotes: 13