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!
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__)"
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
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
.
$which python
/usr/local/bin/python
The output is the same from all my 3 machines
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.
But it works on the machine with CentOS6.5
tacx32: 32bit(uname -m command return i686), with CentOS6.5, pip command is ok
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 :-(
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
Eventually, on those 2 machines that pip command gave "ImportError" I change the 1st line of /usr/local/bin/pip from
to
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!
I'm going to close this, it sounds like a broken install.
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
.
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
install Python3.x by compiling source code
@pfmoore
Aha! Note
$cat /usr/local/bin/pip
...
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!
Indeed I did sudo rm /usr/local/bin/pip*
, then sudo apt-get install python-pip
and it seem to be fixed.
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/
@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 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.
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
Most helpful comment
Indeed I did
sudo rm /usr/local/bin/pip*
, thensudo apt-get install python-pip
and it seem to be fixed.