更新 - sys.path 的值

更新 - sys.path 的值

我正在尝试清理 MacBook Pro (macOS 10.13.4) 上的各种 Python 安装,方法是删除除原始系统 Python (当前版本的 macOS 为 2.7.2) 之外的所有内容。我曾经安装过来自 python.org、macports 和 homebrew 的程序,我想我已经能够删除这些安装涉及的所有内容,但是当我尝试安装模块时,我的系统 Python 仍然会对我大喊大叫。

删除自制的 python 和 pip 安装并从 macports 安装中删除旧文件夹后,我更新了 ~/.bash_profile,使其仅包含 .bashrc 配置和 iTerm2 实用程序。然后,我使用 easy_install 为系统 python 安装了 PIP。但是,当我尝试安装软件包(例如 voltron)时,出现以下错误,并且安装未完成。

matplotlib 1.3.1 requires nose, which is not installed.
python-dateutil 2.6.1 has requirement six>=1.5, but you'll have six 1.4.1 which is incompatible.
prompt-toolkit 1.0.15 has requirement six>=1.9.0, but you'll have six 1.4.1 which is incompatible.
blessed 1.14.2 has requirement six>=1.9.0, but you'll have six 1.4.1 which is incompatible.
matplotlib 1.3.1 has requirement numpy>=1.5, but you'll have numpy 1.8.0rc1 which is incompatible.

which python回报/usr/bin/pythonwhich pip回报/usr/local/bin/pip

我想让我的电脑恢复到出厂时的状态,但我不想进行清除并重新安装。我曾尝试使用 macOS 恢复模式重新安装 macOS,但错误并没有改变,所以似乎在某个地方还残留着对这些软件包的引用。我该如何恢复 Python 的原始状态?


$> pip -V
pip 10.0.0b2 from /Library/Python/2.7/site-packages/pip-10.0.0b2-py2.7.egg/pip (python 2.7)

看起来它确实最终安装了 Voltron,但它仍然显示缺少依赖项的错误。当我尝试安装其中一个(在本例中为六个)时,会发生以下情况

$> pip install --user six
Requirement already satisfied: six in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (1.4.1)
python-dateutil 2.6.1 has requirement six>=1.5, but you'll have six 1.4.1 which is incompatible.
prompt-toolkit 1.0.15 has requirement six>=1.9.0, but you'll have six 1.4.1 which is incompatible.
blessed 1.14.2 has requirement six>=1.9.0, but you'll have six 1.4.1 which is incompatible.
matplotlib 1.3.1 has requirement numpy>=1.5, but you'll have numpy 1.8.0rc1 which is incompatible.

更新 - sys.path 的值

$> python -c "import os, sys; print(os.linesep.join(sys.path))"

/Library/Python/2.7/site-packages/pip-10.0.0b2-py2.7.egg
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/Users/emroch/Library/Python/2.7/lib/python/site-packages
/Library/Python/2.7/site-packages
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC

答案1

我在使用 PIP 安装软件包时遇到了类似的问题,问题的原因似乎是这样的 https://github.com/pypa/pip/issues/5196

我可以按照这里提出的方法解决问题 https://stackoverflow.com/questions/27630114/matplotlib-issue-on-os-x-importerror-cannot-import-name-thread

sudo pip uninstall python-dateutil
sudo pip install python-dateutil==2.2

来自@oriol-nieto 的回答

python 使用的是旧版本的 six,我通过输入以下内容将其删除:

rm -rf /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.*

相关内容