[英]Upgrading setuptools on OSX El Capitan
我正在嘗試升級 setuptools。 好吧,實際上我正在嘗試升級 ansible,但它正在嘗試升級 setuptools 並且失敗了。 嘗試自己做也失敗了。 即使嘗試卸載它也失敗了
$ sudo -H pip install --upgrade setuptools
Collecting setuptools
Using cached setuptools-18.4-py2.py3-none-any.whl
Installing collected packages: setuptools
Found existing installation: setuptools 1.1.6
Uninstalling setuptools-1.1.6:
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg/pip/basecommand.py", line 211, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg/pip/commands/install.py", line 311, in run
root=options.root_path,
File "/Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg/pip/req/req_set.py", line 640, in install
requirement.uninstall(auto_confirm=True)
File "/Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg/pip/req/req_install.py", line 716, in uninstall
paths_to_remove.remove(auto_confirm)
File "/Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg/pip/req/req_uninstall.py", line 125, in remove
renames(path, new_path)
File "/Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg/pip/utils/__init__.py", line 315, in renames
shutil.move(old, new)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 299, in move
copytree(src, real_dst, symlinks=True)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 208, in copytree
raise Error, errors
Error: [('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.py', '/tmp/pip-OyTXsR-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.py', "[Errno 1] Operation not permitted: '/tmp/pip-OyTXsR-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.pyc', '/tmp/pip-OyTXsR-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.pyc', "[Errno 1] Operation not permitted: '/tmp/pip-OyTXsR-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.py', '/tmp/pip-OyTXsR-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.py', "[Errno 1] Operation not permitted: '/tmp/pip-OyTXsR-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.pyc', '/tmp/pip-OyTXsR-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.pyc', "[Errno 1] Operation not permitted: '/tmp/pip-OyTXsR-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib', '/tmp/pip-OyTXsR-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib', "[Errno 1] Operation not permitted: '/tmp/pip-OyTXsR-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib'")]
我不知道出了什么問題。 查看/System/Library/Frameworks/Python.framework/Versions/2.7/
和下面的所有文件,每個文件都歸root:wheel
我該如何解決?
這是由於 OS X El Capitan 中引入的系統完整性保護造成的。
將--user python
添加到命令允許它工作。
換句話說
pip install --upgrade setuptools --user python
問題是 Python 庫沖突,再加上 Mac OS 上的系統完整性保護 (SIP) 保護系統 Python 庫。
我認為最好的解決方案是卸載並重新安裝您自己的 Python 安裝,並將其與受 SIP 保護的 Mac OS 提供的 Python 庫分開。
我贊成禁用 SIP,因為我希望 SIP 成為任何未來 Mac OS 版本的一部分,而 SIP 不是這里的原因,它只是暴露了 Python 庫沖突的問題。
我在嘗試安裝 ansible 時也遇到了這個問題。
當我按照 Mac OS 的 ansible 安裝說明進行操作時,我的問題就開始了,即通過 pip 安裝並使用easy_install
安裝 pip,如通過 Pip 的最新版本中所述
問題是當以這種方式安裝 pip 時, easy_install
是 Mac OS 在/usr/bin/easy_install
處提供的easy_install
,但它會寫入/Library/Python/2.7/site-packages/easy-install.pth
處的easy-install.pth
文件/Library/Python/2.7/site-packages/easy-install.pth
並且該文件引用了 Mac OS 提供的 Python 庫。
隨后使用pip install ansible
ansible pip install ansible
然后報告說 Mac OS 提供的 Python 庫滿足 setuptools 要求,位於/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Ansible 需要 setuptools 但不指定版本。 另一個依賴包 paramiko 需要 setuptools >= 11.3,但是在通過 pip 安裝 ansible 時似乎沒有檢查。 當你嘗試運行 ansible 時,它抱怨 setup tools 是 1.1.6 這是 Mac OS 提供的 setuptools 版本,現在受 SIP 保護,因此無法升級。
我沒有禁用 SIP,而是通過卸載本地 Python 來解決此問題,如https://docs.python.org/2.7/using/mac.html#getting-and-installing-macpython 所示,然后再次下載並安裝。
如果你擔心 rm,你可以 mv 代替
卸載我做了
sudo rm -rf /Library/Python
sudo rm -rf /Applications/Python\ 2.7/
sudo rm /usr/local/bin/ansible # executable
sudo rm /usr/local/bin/python* # symlinks to /Library/Python/2.7
sudo rm /usr/local/bin/easy_install*
# and so on for references to /Library/Python/2.7 in /usr/local/bin
然后我從https://www.python.org/downloads/下載了 Mac OS X 的 2.7.13 安裝程序包並安裝了它。
這種安裝在一個地方蟒蛇和PIP /Library/Frameworks/Python.framework/Versions/2.7
並符號連接/usr/local/bin
以及前面加上/Library/Frameworks/Python.framework/Versions/2.7
我的$ PATH。 這使所有內容與/System/Library/Frameworks/Python.framework
和/usr/bin
Mac OS 提供的庫/System/Library/Frameworks/Python.framework
,以便我得到
which pip
/Library/Frameworks/Python.framework/Versions/2.7/bin/pip
然后我用pip install ansible
然后當我運行which ansible
我得到
/Library/Frameworks/Python.framework/Versions/2.7/bin/ansible
並在pip list
setuptools (28.8.0)
six (1.10.0)
ansible 現在對我有用,因為新安裝沒有引用 Mac OS Python 庫。
請注意,由於安裝程序設置了 $PATH, which python
現在是/Library/Frameworks/Python.framework/Versions/2.7/bin/python
而/usr/local/bin/python
是指向此的符號鏈接。
如果您想要系統 Python,則必須使用 /usr/bin/python 或更改 $PATH
答案是您無法在 OSX 上為 OS 附帶的工廠 Python 更新 setuptools。 原因是/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
中的文件不能被用戶刪除或修改。 不僅是普通用戶,即使您擁有 root 權限,您也無法修改這些文件。
當然,您可以使用其他各種方法來安裝更新版本的 setuptools,但這不會覆蓋默認的系統包。 這意味着如果您使用--user python
標志的建議路線,或者您選擇在沒有 root 的情況下將它們安裝到~/Library
,這些將不會覆蓋系統文件版本。
您或 root 無法修改系統默認值的原因是 El Capitan+ 中的 SIP 權限限制。 您可以禁用 SIP,但通常不建議這樣做。
相反,唯一合理的解決方案是使用 python virtualenv。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.