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

Comments

Projects
None yet
10 participants
@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

This comment has been minimized.

Show comment
Hide comment
@Ivoz

Ivoz Jul 9, 2014

Member

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__)"

Member

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-

This comment has been minimized.

Show comment
Hide comment
@ying-wang-

ying-wang- 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

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

This comment has been minimized.

Show comment
Hide comment
@pfmoore

pfmoore Jul 9, 2014

Member

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.

Member

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-

This comment has been minimized.

Show comment
Hide comment
@ying-wang-

ying-wang- Jul 9, 2014

$which python
/usr/local/bin/python

The output is the same from all my 3 machines

ying-wang- commented Jul 9, 2014

$which python
/usr/local/bin/python

The output is the same from all my 3 machines

@pfmoore

This comment has been minimized.

Show comment
Hide comment
@pfmoore

pfmoore Jul 9, 2014

Member

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.

Member

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-

This comment has been minimized.

Show comment
Hide comment
@ying-wang-

ying-wang- 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

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

This comment has been minimized.

Show comment
Hide comment
@pfmoore

pfmoore Jul 9, 2014

Member

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 :-(

Member

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-

This comment has been minimized.

Show comment
Hide comment
@ying-wang-

ying-wang- 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- 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-

This comment has been minimized.

Show comment
Hide comment
@ying-wang-

ying-wang- 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!

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

This comment has been minimized.

Show comment
Hide comment
@dstufft

dstufft Nov 12, 2014

Member

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

Member

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

This comment has been minimized.

Show comment
Hide comment
@Ivoz

Ivoz Dec 10, 2014

Member

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.

Member

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

This comment has been minimized.

Show comment
Hide comment
@1Gian

1Gian 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

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

This comment has been minimized.

Show comment
Hide comment
@isudox

isudox Oct 28, 2015

install Python3.x by compiling source code

isudox commented Oct 28, 2015

install Python3.x by compiling source code

@abhishekangira

This comment has been minimized.

Show comment
Hide comment
@abhishekangira

abhishekangira 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!

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

This comment has been minimized.

Show comment
Hide comment
@pawamoy

pawamoy 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.

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

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost 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/

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

This comment has been minimized.

Show comment
Hide comment
@piotr-dobrogost

piotr-dobrogost 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?

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

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost 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.

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

This comment has been minimized.

Show comment
Hide comment
@gyrocaptain

gyrocaptain 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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment