更新 - sys.path 的值

更新 - sys.path 的值

我正在嘗試透過刪除除原始系統 python(當前版本的 macOS 為 2.7.2)之外的所有內容來清理 MacBook Pro(macOS 10.13.4)上的各種 Python 安裝。我曾經從 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 使用的是舊版本的 6,我輸入以下內容將其刪除:

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

相關內容