OSX El Capitan:sudo pip install OSError:[Errno:1] 不允许操作 [英] OSX El Capitan: sudo pip install OSError: [Errno: 1] Operation not permitted

查看:32
本文介绍了OSX El Capitan:sudo pip install OSError:[Errno:1] 不允许操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我跑步时:

sudo pip install ipython

我收到以下错误

OSError: [Errno: 1] Operation not allowed: '/System/Library/Frameworks/Python.framework/Versions/2.7/share'

OSError: [Errno: 1] Operation not permitted: '/System/Library/Frameworks/Python.framework/Versions/2.7/share'

执行的最后一个命令尝试创建上面给出的目录.

The last command executed tries to create the directory given above.

此外,以下命令无法安装 iPython 且不提供任何错误.

Also, the following command fails to install iPython without providing any errors.

sudo pip install --user python

(我在 Mac OS X El Capitan 上以防其他人在这个操作系统上看到同样的问题.)

(I am on Mac OS X El Capitan in case other folks on this OS see the same issue.)

推荐答案

告诉 sudo pip install 的说明本质上是错误的.

Instructions telling sudo pip install are inherently wrong.

如果有任何教程说你应该做 sudo pip 然后请针对这个包提交错误.作者正在对 Python 社区进行教育,因为时间已经证明 sudo pip 是一种错误的做法.

If there is any tutorial out there which says you should do sudo pip then please file a bug against this package. The author is dis-educating Python community, as time has proven sudo pip to be a broken practice.

OSX El Capitan 引入了一种机制来防止损坏操作系统文件./System/Library/Frameworks/Python.framework/Versions/2.7/share 是受保护的位置之一.普通用户没有理由在那里放置或写入任何文件.这是因为操作系统本身依赖于这些文件,并且 sudo pip 会无条件地覆盖它们.通常坏事不会发生,但机会是有的.Apple 希望保护他们的操作系统用户不小心阻止他们的安装.

OSX El Capitan introduced a mechanisms to prevent damaging the operating system files. /System/Library/Frameworks/Python.framework/Versions/2.7/share is one of the protected locations. A normal user has no reason to put or write any files there. This is because the operating system itself relies on these files and sudo pip, with all force given from the above, would unconditionally overwrite them. Usually bad things would not happen, but the chances are there. Apple wants to protect their OS users to accidentally bricking their installation.

相反,您需要安装一个 Python 包,例如 IPython,本地到您用户的主文件夹.最简单的方法是创建一个虚拟环境激活它,然后在虚拟环境中运行pip.

Instead, you need to install a Python package, like IPython, locally to the home folder of your user. The easiest way is to create a virtual environment, activate it and then run pip in the virtual environment.

示例:

cd ~  # Go to home directory
virtualenv my-venv
source my-venv/bin/activate
pip install IPython

更多信息

如何创建虚拟环境.

或者,您应该能够执行 pip install --user.但同样,不需要 sudo,您需要手动设置 PATH 环境变量.

Alternatively, one should be able to do pip install --user. But again, no sudo needed and you need to manually set up PATH environment variable.

这篇关于OSX El Capitan:sudo pip install OSError:[Errno:1] 不允许操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆