我的OSX系统和Python出了问题,无论我怎么搜索都没能解决。我已经卸载了除了系统自带的Python包之外的所有Python文件,并从python.org开始重新安装Python,并安装了pip。
现在......不确定下面的行为是否是问题的一部分,但它对我来说似乎很奇怪:
我运行了两次Python。一次使用sudo,一次没有。没有使用sudo时,我无法访问pip。发生了什么?
$ sudo /Library/Frameworks/Python.framework/Versions/2.7/bin/python
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pip
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pip
然而...
$ /Library/Frameworks/Python.framework/Versions/2.7/bin/python
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pip
>>>
我已经参考了:sudo python runs old python version
我的.bash_profile没有任何内容,其他配置文件也是一样。
我所做的就是以下几步:
export PYTHONPATH=/lib/python2.7/site-packages/
ls $PYTHONPATH
返回:
_markerlib pip pkg_resources.pyc setuptools-8.0.1.dist-info virtualenv.pyc
easy_install.py pip-1.5.6.dist-info setuptools virtualenv-1.11.6.dist-info virtualenv_support
easy_install.pyc pkg_resources.py setuptools-7.0.dist-info virtualenv.py
which pip
返回:
/bin/pip
sudo
shell 的值。在sudo
运行之前,你的当前 shell 会插入任何双引号中的变量。使用单引号可以查看根 shell 实例中变量的实际值。 - tripleee