我有一个CentOS服务器(5.6),上面有Python 2.4.3。我在/opt
中安装了另一个本地安装的Python(2.7.5),并创建了如下/usr/local/bin/python2.7
和/usr/local/python2.7
的软链接。我想使用pip
安装python-requests。使用命令pip install requests
安装时,我收到以下错误:
root ~/ff_test_ff # pip install requests
Unpacking ./requests
Running setup.py egg_info for package from file:///root/ff_test_ff/requests
Traceback (most recent call last):
File "<string>", line 14, in ?
File "/tmp/pip-MM685m-build/setup.py", line 6, in ?
import requests
File "requests/__init__.py", line 58
from . import utils
^
SyntaxError: invalid syntax
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 14, in ?
File "/tmp/pip-MM685m-build/setup.py", line 6, in ?
import requests
File "requests/__init__.py", line 58
from . import utils
^
SyntaxError: invalid syntax
----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /root/.pip/pip.log
我假设它仍在尝试使用Python 2.4。我checked here说不支持2.4。那么如何运行pip install
命令但是使用python2.7呢?
你需要设置PYTHONPATH
/ PYTHONHOME
like here
你也可以尝试安装virtualenv
您可能应该(重新)为新的Python版本显式安装新版本的pip。在pip installation instructions page它说
pip适用于CPython版本2.6,2.7,3.1,3.2,3.3以及pypy。
安装时,请务必使用较新版本的Python而不是旧版本。