I tried to install pip but encountered some problems

I started coding recently with codeacademy´s course “Computer Sience” and was working on this part:

https://www.codecademy.com/paths/computer-science/tracks/cspath-python-objects/modules/cspath-modules/videos/learn-python3-pipenv

When I try to run the command <pip --version> terminal prints out the following message:

Traceback (most recent call last):
File “/usr/local/bin/pip”, line 7, in
from pip import main
ImportError: cannot import name main

I feel a little bit stuck here. I tried to install pip as the documentation told me to do, but terminal prints out the same message over and over again. Can someone tell me what it means and what I should do now?

(pip documentation: https://pip.pypa.io/en/stable/installing/)

1 Like

a little googling teaches me that quite a few people have this issue, this seems the most popular fix:

https://github.com/pypa/pip/issues/5221#issuecomment-381568428

other tickets i found:

https://github.com/pypa/pip/issues/5240
https://github.com/pypa/pip/issues/5447

the issue mostly seems to related to pip10, but given you can’t run pip --version its difficult to say what version you have… that sucks…

2 Likes

I reinstalled pip, I now run version 19.0.2 but I am still encoutering the “cannot import name main” issue. I tried to run the following:

from pip._internal import main as _main

which lead to this message:

from: can’t read /var/mail/pip._internal
Michaels-MBP:~ michael$ from pip import main
from: can’t read /var/mail/pip

Does that tell anything?

1 Like

these kind of error messages are really difficult, given the complexities of the tools (like pip). The only way to solve them, is by googling, gathering information and trying various things.

if that really doesn’t work, i recommend you to make a ticket on pips github page, given there are people who have worked on pip, and might be able to help you better

2 Likes

You’re probably using the wrong pip, having multiple installations of it.
You can let python find the right one instead:

python3 -m pip --version

Which really ought to be there in recent versions of python unless you went out of your way to break it, or if you installed it using some repository which packages python and pip separately.

1 Like
python3 -m pip --version

got back this message:

/Library/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python: can’t open file ‘pip’: [Errno 2] No such file or directory

I read somewhere that pip usually gets installed with python3 together. Instead of pip I tried pip3, which basicly solved the problem:

pip3 --version

pip 19.0.2 from /Users/michael/Library/Python/3.7/lib/python/site-packages/pip (python 3.7)

After that I followed the instructions given in the video and it worked as expected!

1 Like

pip3 and python3 -m pip should do the same thing (if one inspects the pip3 executable it is a script that runs the module pip), so I’d say something is still wrong.
But if you can install packages and then import them then I suppose that’s about as far as you might want to care for now.

1 Like