1

我基本上与 Python 2.7 中描述的情况完全相同
,系统、PIP 和 Virtualenv 仍在使用 2.6 - 如何将它们切换为使用 2.7

也就是说,我的 mac 默认使用 Python 2.7,而 Pip 安装到 2.6

我按照Ned Deily 的回答,用我的默认 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,但根环境指向 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)

所以我的根指向 2.6 但sudo pip --version指向 pip 2.7,而我的本地用户指向 2.7 但pip --version指向 pip 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  
4

2 回答 2

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。在我看来,您有两个选择:

  1. 您可以使用 Apple 设置来切换系统 python 版本:$ defaults write com.apple.versioner.python Version 2.7$ export VERSIONER_PYTHON_VERSION=2.7. (有关man python您的特定 OSX 版本的更多详细信息,请参阅。)
  2. 您可以使用 pip python 特定版本。(例如pip-2.7:)
于 2012-10-03T20:42:53.337 回答
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)'
于 2012-10-03T20:59:08.187 回答