pip install does not work when trying to install virtualenv, requests or pex on CentOS6. I am on python2.6 and pip 9.0.1. Can anyone tell me why is this happening?
(pex_build)[root@pex pex_build]# pip install virtualenv
Output:
Traceback (most recent call last):
File "/opt/pex_build/bin/pip", line 7, in
from pip._internal import main
File "/opt/pex_build/lib/python2.6/site-packages/pip/_internal/__init__.py", line 42, in
from pip._internal import cmdoptions
File "/opt/pex_build/lib/python2.6/site-packages/pip/_internal/cmdoptions.py", line 16, in
from pip._internal.index import (
File "/opt/pex_build/lib/python2.6/site-packages/pip/_internal/index.py", line 526
{str(c.version) for c in all_candidates},
^
SyntaxError: invalid syntax
Command:
(pex_build) [root@pex pex_build]# pip install requests pex
Output:
Traceback (most recent call last):
File "/opt/pex_build/bin/pip", line 7, in
from pip._internal import main
File "/opt/pex_build/lib/python2.6/site-packages/pip/_internal/__init__.py", line 42, in
from pip._internal import cmdoptions
File "/opt/pex_build/lib/python2.6/site-packages/pip/_internal/cmdoptions.py", line 16, in
from pip._internal.index import (
File "/opt/pex_build/lib/python2.6/site-packages/pip/_internal/index.py", line 526
{str(c.version) for c in all_candidates},
^
SyntaxError: invalid syntax
Also curl gives the similar error, when trying to get get-pip.py
Command:
(pex_build) [root@pex pex_build]# curl https://bootstrap.pypa.io/get-pip.py | python
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1602k 100 1602k 0 0 7373k 0 --:--:-- --:--:-- --:--:-- 14.6M
Traceback (most recent call last):
File "", line 20636, in
File "", line 197, in main
File "", line 82, in bootstrap
File "/tmp/tmp5zrn_f/pip.zip/pip/_internal/__init__.py", line 42, in
File "/tmp/tmp5zrn_f/pip.zip/pip/_internal/cmdoptions.py", line 16, in
File "/tmp/tmp5zrn_f/pip.zip/pip/_internal/index.py", line 526
{str(c.version) for c in all_candidates},
^
SyntaxError: invalid syntax
解决方案
The problem is your version of pip is broken with Python 2.6. If you upgrade to 9.0.3 it should work again.
pip install pip==9.0.3
If you are unable to upgrade pip using pip, you could re-install the package as well using your local package manager, and then upgrade to pip 9.0.3.
Keep in mind that if you are using virtual environments it is recommended that you upgrade virtualenv as well so that your virtual environments will have pip 9.0.3 as well.
pip install virtualenv==15.2.0
Be careful though to not upgrade to a version of pip higher than 9.0.3 or virtualenv higher than 15.2.0 as Python 2.6 support was removed with those versions, as mentioned by Prateek.