Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: No module named pip #1918

Closed
ying-wang- opened this issue Jul 8, 2014 · 19 comments
Closed

ImportError: No module named pip #1918

ying-wang- opened this issue Jul 8, 2014 · 19 comments

Comments

@ying-wang-
Copy link

@ying-wang- ying-wang- commented Jul 8, 2014

I installed python2.7.7 on CentOS 5.10
then run python get-pip.py which is successful.
now when I type pip it gives
Traceback (most recent call last):
File "/usr/local/bin/pip", line 7, in ?
from pip import main
ImportError: No module named pip

I tried on another machine of CentOS 5.10 and it is the same result. But it is ok on machine of CentOS6.5.

Could anyone point out what is wrong with my installation?

Thanks!

@Ivoz
Copy link
Member

@Ivoz Ivoz commented Jul 9, 2014

could you paste the output of these commands please

$ python -V
$ cat /usr/local/bin/pip
$ python -m pip -V
$ python -c "import pip; print(pip.__version__)"

@ying-wang-
Copy link
Author

@ying-wang- ying-wang- commented Jul 9, 2014

I have 3 machines:
tacx32: 32bit(uname -m command return i686), with CentOS6.5, pip command is ok
tac03: 64bit(uname -m command return x86_64), with CentOS5.10, pip command gives ImportError
tac06: 32bit(uname -m command return i686), with CentOS5.10, pip command gives ImportError

The output of those commands are the same frrom all the three machines.

$python -V
Python 2.7.7

$cat /usr/local/bin/pip
#!/usr/bin/python

# -*- coding: utf-8 -*-
import re
import sys

from pip import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

$python -m pip -V
pip 1.5.6 from /usr/local/lib/python2.7/site-packages (python 2.7)

$python -c "import pip; print(pip.__version__)"
1.5.6
@pfmoore
Copy link
Member

@pfmoore pfmoore commented Jul 9, 2014

Could you also report the outut of which python? This feels to me very much like pip is installed in a version of Python that is not /usr/bin/python.

@ying-wang-
Copy link
Author

@ying-wang- ying-wang- commented Jul 9, 2014

$which python
/usr/local/bin/python

The output is the same from all my 3 machines

@pfmoore
Copy link
Member

@pfmoore pfmoore commented Jul 9, 2014

Aha! Note

$cat /usr/local/bin/pip
#!/usr/bin/python
...

So the version of pip in /usr/local/bin is pointing at Python from /usr/bin. This is wrong. I don't know how it happened, though.

@ying-wang-
Copy link
Author

@ying-wang- ying-wang- commented Jul 9, 2014

But it works on the machine with CentOS6.5
tacx32: 32bit(uname -m command return i686), with CentOS6.5, pip command is ok

@pfmoore
Copy link
Member

@pfmoore pfmoore commented Jul 9, 2014

Do you have pip installed in /usr/bin/python's site-packages on that machine? If not, I don't see how your output on that machine is consistent with what you're seeing, sorry :-(

@ying-wang-
Copy link
Author

@ying-wang- ying-wang- commented Jul 9, 2014

I installed python2.7.7 and then run "python get-pip.py" on all the 3 machines

I run the following commands on tacx32 machine (pip is ok on this machine) and there is no pip there

$ls -l /usr/bin/pyt*
-rwxr-xr-x 2 root root 6088 Jan 22 01:37 /usr/bin/python
lrwxrwxrwx 1 root root 6 Jun 17 12:19 /usr/bin/python2 -> python
-rwxr-xr-x 2 root root 6088 Jan 22 01:37 /usr/bin/python2.6
-rwxr-xr-x 1 root root 1418 Jan 22 01:37 /usr/bin/python2.6-config
lrwxrwxrwx 1 root root 16 Jun 17 12:23 /usr/bin/python-config -> python2.6-config

$ls -l /usr/bin/site*
ls: cannot access /usr/bin/site*: No such file or directory

@ying-wang-
Copy link
Author

@ying-wang- ying-wang- commented Jul 9, 2014

Eventually, on those 2 machines that pip command gave "ImportError" I change the 1st line of /usr/local/bin/pip from
#!/usr/bin/python
to
#!/usr/local/bin/python

Then run the pip command and it works.
But I don't think I should do this. But anyway it allows me to install python modules that I need. Hopefully any of you can see the problem and fix it so other people won't suffer.

Thanks again for all the inputs from all of you!

@dstufft
Copy link
Member

@dstufft dstufft commented Nov 12, 2014

I'm going to close this, it sounds like a broken install.

@dstufft dstufft closed this Nov 12, 2014
@Ivoz
Copy link
Member

@Ivoz Ivoz commented Dec 10, 2014

Somehow pip thought its python was from /usr/bin rather than /usr/local/bin. Maybe when you ran get-pip.py it ran from the /usr/bin/python instead of the /usr/local/bin/python.

@1Gian
Copy link

@1Gian 1Gian commented Oct 5, 2015

I also got the same problem

$ python -V
$ cat /usr/local/bin/pip
$ python -m pip -V
$ python -c "import pip; print(pip.__version__)"

not working on desktop ubuntu 14.4

@isudox
Copy link

@isudox isudox commented Oct 28, 2015

install Python3.x by compiling source code

@abhishekangira
Copy link

@abhishekangira abhishekangira commented Dec 22, 2015

@pfmoore
Aha! Note

$cat /usr/local/bin/pip
#!/usr/bin/python
...
So the version of pip in /usr/local/bin is pointing at Python from /usr/bin. This is wrong. I don't know how it happened, though.

Thanks a lot man! I was having the same problem, and all i did was to delete the pip files from local/bin. And it woked!

@pawamoy
Copy link

@pawamoy pawamoy commented Jan 15, 2016

Indeed I did sudo rm /usr/local/bin/pip*, then sudo apt-get install python-pip and it seem to be fixed.

@ghost
Copy link

@ghost ghost commented Apr 5, 2016

I had the same problem as the OP on CentOS 5.11, and I believe I know why. Maybe it happens to anyone using make altinstall to build Python?

CentOS 5.11 has Python 2.4 by default. I downloaded Python 2.7.11 and built using this --
sudo ./configure --enable-unicode=ucs4 && sudo make altinstall

The three pip scripts created in /usr/local/bin (pip, pip2, and pip2.7) all had #!/usr/bin/python in the shebang line. That points to the default Python (2.4). Editing them to refer to /usr/local/bin/python as suggested above solves the problem.

I encountered this while setting up a CentOS 5.11 VM on which to build Linux wheels for Python. In case anyone cares about the context, here's my complete OS setup & Python build instructions:
http://blog.pyspoken.com/2016/03/27/how-to-set-up-centos-to-build-linux-wheels-for-python/

@piotr-dobrogost
Copy link

@piotr-dobrogost piotr-dobrogost commented Apr 6, 2016

@philip-semanchuk
Python Setup and Usage | Using Python on Unix platforms | Python-related paths and files says this

These are subject to difference depending on local installation conventions; prefix (${prefix}) and exec_prefix (${exec_prefix}) are installation-dependent and should be interpreted as for GNU software; they may be the same.
For example, on most Linux systems, the default for both is /usr.

Are you sure you installed your custom Python in /usr/local and not in /usr?

@ghost
Copy link

@ghost ghost commented Apr 6, 2016

@piotr-dobrogost Yes, CentOS comes with the system Python (2.4) in /usr. That's why I installed my Python with make altinstall.

[me@localhost ~]$ /usr/bin/python -V
Python 2.4.3
[me@localhost ~]$ /usr/local/bin/python -V
Python 2.7.11

Reviewing my script, I realized that I also downloaded get-pip.py and ran sudo python get-pip.py after installing Python, so I guess it was during that step where pip got pointed to the wrong Python.

@gyrocaptain
Copy link

@gyrocaptain gyrocaptain commented May 8, 2016

Reviewing my script, I realized that I also downloaded get-pip.py and ran sudo python get-pip.py after installing Python, so I guess it was during that step where pip got pointed to the wrong Python.

If python was already installed and you installed a new version, then the hash that bash uses to locate binaries in PATH may not yet have been updated to point to the new install. After the install, did python -V show the new version 2.7.11? If not, then this is likely the problem.

You can force bash to delete the hash for python and create it with hash -d python

@lock lock bot added the S: auto-locked label Jun 4, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
10 participants
You can’t perform that action at this time.