我基本上有完全相同的情况,如中所述 Python 2.7 on System, PIP and Virtualenv still using 2.6 - How do I switch them to use 2.7
也就是说,我的mac默认使用Python 2.7,而Pip正在安装到2.6
我跟着Ned Deily's answer并使用我的默认Python安装了easy_install,并用它来安装Pip。
现在我明白了:
$ which easy_install
/Library/Frameworks/Python.framework/Versions/2.7/bin/easy_install
$ which pip
/Library/Frameworks/Python.framework/Versions/2.7/bin/pip
好吧,看起来不错。但是,我也得到了这个:
$ pip --version
pip 1.0.2 from /Library/Python/2.6/site-packages/pip-1.0.2-py2.6.egg (python 2.6)
并且Pip 仍然安装到2.6。
我错过了什么?
更新:
也许这是一个线索 - 我刚刚运行了以下内容:
$ ls -la /usr/bin/python*
-rwxr-xr-x 2 root wheel 86000 May 4 2011 /usr/bin/python
-rwxr-xr-x 5 root wheel 925 May 4 2011 /usr/bin/python-config lrwxr-xr-x 1 root wheel 75 May 4 2011 /usr/bin/python2.5 ->
../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5
lrwxr-xr-x 1 root wheel 82 May 4 2011
/usr/bin/python2.5-config ->
../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5-config
lrwxr-xr-x 1 root wheel 75 May 4 2011 /usr/bin/python2.6 ->
../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
lrwxr-xr-x 1 root wheel 82 May 4 2011
/usr/bin/python2.6-config ->
../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6-config
-rwxr-xr-x 2 root wheel 86000 May 4 2011 /usr/bin/pythonw lrwxr-xr-x 1 root wheel 76 May 4 2011 /usr/bin/pythonw2.5 ->
../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/pythonw2.5
lrwxr-xr-x 1 root wheel 76 May 4 2011 /usr/bin/pythonw2.6 ->
../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/pythonw2.6
和
$ ls -la /usr/local/bin/python*
lrwxr-xr-x 1 ykessler wheel 68
Nov 14 2011 /usr/local/bin/python ->
../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python
lrwxr-xr-x 1 ykessler wheel 71 Nov 14 2011
/usr/local/bin/python-32 ->
../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python-32
lrwxr-xr-x 1 ykessler wheel 75 Nov 14 2011
/usr/local/bin/python-config ->
../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python-config
lrwxr-xr-x 1 ykessler wheel 71 Nov 14 2011
/usr/local/bin/python2.7 ->
../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x 1 ykessler wheel 74 Nov 14 2011
/usr/local/bin/python2.7-32 ->
../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-32
lrwxr-xr-x 1 ykessler wheel 78 Nov 14 2011
/usr/local/bin/python2.7-config ->
../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
lrwxr-xr-x 1 ykessler wheel 69 Nov 14 2011 /usr/local/bin/pythonw
-> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw
lrwxr-xr-x 1 ykessler wheel 72 Nov 14 2011
/usr/local/bin/pythonw-32 ->
../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw-32
lrwxr-xr-x 1 ykessler wheel 72 Nov 14 2011
/usr/local/bin/pythonw2.7 ->
../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7
lrwxr-xr-x 1 ykessler wheel 75 Nov 14 2011
/usr/local/bin/pythonw2.7-32 ->
../../../Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7-32
所以看起来我的用户环境指向2.7,但root环境指向2.6?我该如何调和这两个?
更新2:
好的,只需再拧一下螺丝:
$ sudo pip --version
pip 1.2.1 from /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg (python 2.7)
$ pip --version
pip 1.0.2 from /Library/Python/2.6/site-packages/pip-1.0.2-py2.6.egg (python 2.6)
所以我的root指向2.6但sudo pip --version
指向pip 2.7,
而我的本地用户指向2.7但pip --version
指向点2.6
???我的大脑开始炒了。
现在我刚刚做了sudo pip install {module}
并在2.7中正确安装,但我希望我知道发生了什么......
更新3:回答Ned的问题:
$ type pip
pip is /Library/Frameworks/Python.framework/Versions/2.7/bin/pip
$ echo $PATH
/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin
$ which pip
/Library/Frameworks/Python.framework/Versions/2.7/bin/pip
$ ls -l $(which pip)
-rwxr-xr-x 1 ykessler admin 358 Oct 3 15:30 /Library/Frameworks/Python.framework/Versions/2.7/bin/pip
$ sudo bash
bash-3.2# type pip
pip is /Library/Frameworks/Python.framework/Versions/2.7/bin/pip
bash-3.2# echo $PATH
/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin
bash-3.2# ls -l $(which pip)
-rwxr-xr-x 1 ykessler admin 358 Oct 3 15:30 /Library/Frameworks/Python.framework/Versions/2.7/bin/pip
答案 0 :(得分:1)
在我的系统上,我有几个easy_installs:
$ ls /usr/bin/easy_install*
/usr/bin/easy_install /usr/bin/easy_install-2.5 /usr/bin/easy_install-2.6 /usr/bin/easy_install-2.7
以及几个点:
$ ls /usr/local/bin/pip*
/usr/local/bin/pip /usr/local/bin/pip-2.5 /usr/local/bin/pip-2.6 /usr/local/bin/pip-2.7
正如您所说,您的用户环境似乎指向2.7,但系统指向2.6。在我看来,你有两个选择:
$ defaults write com.apple.versioner.python Version 2.7
或$ export VERSIONER_PYTHON_VERSION=2.7
。 (有关特定OSX版本的更多详细信息,请参阅man python
。)pip-2.7
)答案 1 :(得分:1)
您可能遇到$ PATH问题或权限问题,或两者兼而有之。试试这个:
type pip
echo $PATH
which pip
ls -l $(which pip)
sudo bash
type pip
echo $PATH
ls -l $(which pip)
更新:在两者下再试一次:
env | grep PYTHON
sudo bash
env | grep PYTHON
然后我会查看site-packages
目录的内容:
cd /Library/Frameworks/Python.framework/Versions/2.7
cd ./lib/python2.7/site-packages/
ls -al
more setuptools.pth
此外:
more $(which pip)
python2.7 -c 'import sys, pprint; pprint.pprint(sys.path)'
sudo python2.7 -c 'import sys, pprint; pprint.pprint(sys.path)'