OSX El Capitan:sudo pip安装OSError:操作不允许

当我运行:

sudo pip安装ipython

我得到以下错误

OSError:[Errno:1]不允许操作:'/System/Library/Frameworks/Python.framework/Versions/2.7/share'

最后执行的命令尝试创build上面给出的目录。

另外,以下命令无法在不提供任何错误的情况下安装iPython。

sudo pip安装 – 用户python

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

告诉sudo pip install指令本质上是错误的。

如果有任何说明你应该做sudo pip教程,请提交一个对这个软件包的bug。 作者正在教育Python社区,因为时间已经certificatesudo pip是一个破坏性的做法。

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

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

例:

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

更多信息

  • 官方Python软件包安装教程 。

  • 如何创build虚拟环境 。

或者,应该可以做pip install --user 。 但是,再次, 不需要sudo ,你需要手动设置PATH环境variables。

我有同样的问题,但使用easy_install "module"解决了我的问题。

我不知道为什么,但pip和easy_install使用不同的安装位置,easy_installselect了正确的。

编辑:没有重新检查,但由于评论; 似乎不同的(OSX和brew-installed)安装会相互干扰,这就是为什么他们提到的工具确实指向不同的位置(因为它们属于不同的安装)。 我明白通常这些工具从一个安装点到同一个文件夹。

你应该重新安装python:$ brew重新安装python

酿造看酿造主页

pip install --ignore-installed six

这将完成这项工作,那么你可以尝试你的第一个命令。

通过http://github.com/pypa/pip/issues/3165

pip3 install <package>来代替pip来解决权限问题。

我有同样的问题。 正如其他人所提到的,不要使用sudo运行pip install。 跑

 brew doctor 

并修复警告,你应该能够继续你的点子安装。

同样的错误

 Installing collected packages: six, pyparsing, packaging, appdirs, setuptools Exception: Traceback (most recent call last): File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py", line 215, in main status = self.run(options, args) File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/install.py", line 342, in run prefix=options.prefix_path, File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_set.py", line 784, in install **kwargs File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 851, in install self.move_wheel_files(self.source_dir, root=root, prefix=prefix) File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 1064, in move_wheel_files isolated=self.isolated, File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py", line 345, in move_wheel_files clobber(source, lib_dir, True) File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py", line 323, in clobber shutil.copyfile(srcfile, destfile) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 83, in copyfile with open(dst, 'wb') as fdst: IOError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/six.py' 

在这里我使用 – 没有sudo来解决这个问题

 $ pip install --user scikit-image h5py keras pygame Collecting scikit-image Downloading http://mirrors.aliyun.com/pypi/packages/65/69/27a1d55ce8f77c8ac757938707105b1070ff4f2ae47d2dc99461bfae4491/scikit_image-0.13.0-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (28.1MB) 100% |████████████████████████████████| 28.1MB 380kB/s Collecting h5py Downloading http://mirrors.aliyun.com/pypi/packages/b7/cc/1c29b0815b12de2c92b5323cad60f724ac8f0e39d0166d0b9dfacbcb70dd/h5py-2.7.0-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (4.5MB) 100% |████████████████████████████████| 4.5MB 503kB/s Requirement already satisfied: keras in /Library/Python/2.7/site-packages Requirement already satisfied: pygame in /Library/Python/2.7/site-packages Requirement already satisfied: matplotlib>=1.3.1 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from scikit-image) Requirement already satisfied: six>=1.7.3 in /Library/Python/2.7/site-packages (from scikit-image) Requirement already satisfied: pillow>=2.1.0 in /Library/Python/2.7/site-packages (from scikit-image) Requirement already satisfied: networkx>=1.8 in /Library/Python/2.7/site-packages (from scikit-image) Requirement already satisfied: PyWavelets>=0.4.0 in /Library/Python/2.7/site-packages (from scikit-image) Collecting scipy>=0.17.0 (from scikit-image) Downloading http://mirrors.aliyun.com/pypi/packages/72/eb/d398b9f63ee936575edc62520477d6c2353ed013bacd656bd0c8bc1d0fa7/scipy-0.19.0-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (16.2MB) 100% |████████████████████████████████| 16.2MB 990kB/s Requirement already satisfied: numpy>=1.7 in /Library/Python/2.7/site-packages (from h5py) Requirement already satisfied: theano in /Library/Python/2.7/site-packages (from keras) Requirement already satisfied: pyyaml in /Library/Python/2.7/site-packages (from keras) Requirement already satisfied: python-dateutil in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from matplotlib>=1.3.1->scikit-image) Requirement already satisfied: tornado in /Library/Python/2.7/site-packages (from matplotlib>=1.3.1->scikit-image) Requirement already satisfied: pyparsing>=1.5.6 in /Users/qiuwei/Library/Python/2.7/lib/python/site-packages (from matplotlib>=1.3.1->scikit-image) Requirement already satisfied: nose in /Library/Python/2.7/site-packages (from matplotlib>=1.3.1->scikit-image) Requirement already satisfied: olefile in /Library/Python/2.7/site-packages (from pillow>=2.1.0->scikit-image) Requirement already satisfied: decorator>=3.4.0 in /Library/Python/2.7/site-packages (from networkx>=1.8->scikit-image) Requirement already satisfied: singledispatch in /Library/Python/2.7/site-packages (from tornado->matplotlib>=1.3.1->scikit-image) Requirement already satisfied: certifi in /Library/Python/2.7/site-packages (from tornado->matplotlib>=1.3.1->scikit-image) Requirement already satisfied: backports_abc>=0.4 in /Library/Python/2.7/site-packages (from tornado->matplotlib>=1.3.1->scikit-image) Installing collected packages: scipy, scikit-image, h5py Successfully installed h5py-2.7.0 scikit-image-0.13.0 scipy-0.19.0 

希望它会帮助遇到类似问题的人!

你完全同意Mikko,但是如果你仍然想这样做,这里是这样的:

  • 在恢复模式下重启(保持cmd + R)
  • 从实用程序打开terminal
  • 使用命令csrutil禁用

由于以下几个原因,很难在El Capitan获得点子:

  1. OS X没有正确设置一些distutilsvariables,因此pip会尝试在/System/Library/下的位置安装辅助文件。 埃尔卡皮坦阻止这个,这是你遇到的错误。
  2. OS X在/System/Library/下包含了一些过期的软件包。 点子往往想升级这些,但不能在埃尔卡皮坦。
  3. OS X将pythonsearch顺序中的/System/Library/ higher放在比/Library/Python/2.7/site-packages (系统范围的python包位置)更高的位置,所以即使您设法安装某些软件包的较新版本,那些仍然被加载,打破了一些依赖。

https://apple.stackexchange.com/a/223163/143849有所有这些解决方法。; 但是,通过标准的Python安装程序Homebrew或Anaconda,您可能最好安装自己的Python版本。

我猜你与其他软件包有冲突。 对我来说是six 。 所以你需要使用这样的命令:

 sudo -H pip install google-api-python-client --upgrade --ignore-installed six 
 This did it for me after 'pip install ipython failed': SF55M:~ 278$ **sudo easy_install ipython** Password: Searching for ipython Best match: ipython 5.4.1 Adding ipython 5.4.1 to easy-install.pth file Installing ipython script to /usr/local/bin Installing iptest2 script to /usr/local/bin Installing iptest script to /usr/local/bin Installing ipython2 script to /usr/local/bin Using /Library/Python/2.7/site-packages Processing dependencies for ipython Finished processing dependencies for ipython SF55M:~ 278$ **pip install ipython** Requirement already satisfied: ipython in /Library/Python/2.7/site-packages Requirement already satisfied: prompt-toolkit<2.0.0,>=1.0.4 in /Library/Python/2.7/site-packages (from ipython) Requirement already satisfied: decorator in /Library/Python/2.7/site- packages (from ipython) Requirement already satisfied: setuptools>=18.5 in /Library/Python/2.7/site- packages/setuptools-19.6.1-py2.7.egg (from ipython) Requirement already satisfied: pickleshare in /Library/Python/2.7/site- packages (from ipython) Requirement already satisfied: pygments in /Library/Python/2.7/site-packages (from ipython) Requirement already satisfied: pexpect; sys_platform != "win32" in /Library/Python/2.7/site-packages (from ipython) Requirement already satisfied: pathlib2; python_version == "2.7" or python_version == "3.3" in /Library/Python/2.7/site-packages (from ipython) Requirement already satisfied: backports.shutil-get-terminal-size; python_version == "2.7" in /Library/Python/2.7/site-packages (from ipython) Requirement already satisfied: simplegeneric>0.8 in /Library/Python/2.7/site-packages (from ipython) Requirement already satisfied: traitlets>=4.2 in /Library/Python/2.7/site- packages (from ipython) Requirement already satisfied: appnope; sys_platform == "darwin" in /Library/Python/2.7/site-packages (from ipython) Requirement already satisfied: six>=1.9.0 in /Library/Python/2.7/site- packages (from prompt-toolkit<2.0.0,>=1.0.4->ipython) Requirement already satisfied: wcwidth in /Library/Python/2.7/site-packages (from prompt-toolkit<2.0.0,>=1.0.4->ipython) Requirement already satisfied: ptyprocess>=0.5 in /Library/Python/2.7/site- packages (from pexpect; sys_platform != "win32"->ipython) Requirement already satisfied: scandir; python_version < "3.5" in /Library/Python/2.7/site-packages (from pathlib2; python_version == "2.7" or python_version == "3.3"->ipython) Requirement already satisfied: enum34; python_version == "2.7" in /Library/Python/2.7/site-packages (from traitlets>=4.2->ipython) Requirement already satisfied: ipython-genutils in /Library/Python/2.7/site- packages (from traitlets>=4.2->ipython) SF55M:~ 212580378$ **ipython** Python 2.7.10 (default, Feb 7 2017, 00:08:15) Type "copyright", "credits" or "license" for more information. IPython 5.4.1 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. 

在[1]中:你真的想退出([y] / n)吗? SF55M:〜278 $

我通过brew安装了python2.7,下面解决了我的问题

brew安装numpy

它安装python3,但它仍然工作,并设置为2.7。

TL; DR $ PATH修复

  1. 使用pip install --user package_name安装应包含CLI可执行文件的软件包。
  2. 启动一个python shell并import package_name
  3. findlib/python/...在输出中发生,并用binreplace它
  4. 这可能是$HOME/Library/Python/2.7/bin

细节

由于macOS 10.11 El Capitan中提供了新的系统完整性保护,您不能再使用sudo pip install 。 我们不会在这里辩论这个好处。

另一个答案解释说,你应该pip install --user是正确的。 但是他们把你送到了后面的小巷弄清楚如何处理你的$PATH以便你可以访问已经安装的可执行文件。 幸运的是,我已经解决了一个无关的问题 。

这是我如何解决我的一个系统上的问题的成绩单。 我只是把它包括在内,而不是为我工作的$PATH ,因为你的系统可能与我的不同。 这个过程应该适用于每个人。

 $ pip install --user jp Collecting jp Downloading jp-0.2.4.tar.gz Installing collected packages: jp Running setup.py install for jp ... done Successfully installed jp-0.2.4 $ python -c 'import jp; print jp' <module 'jp' from '/Users/bbronosky/Library/Python/2.7/lib/python/site-packages/jp/__init__.pyc'> $ find /Users/bbronosky/Library/Python -type f -perm -100 /Users/bbronosky/Library/Python/2.7/bin/jp $ which jp $ echo -e '\n''export PATH=$HOME/Library/Python/2.7/bin:$PATH' >> ~/.bashrc $ bash # starting a new bash process for demo, but you should open a new terminal $ which jp /Users/bbronosky/Library/Python/2.7/bin/jp $ jp usage: jp <expression> <filepath> 

就像你我有同样的问题。 我正在运行El Capitan,并试图用python2.7来安装Juypter以下是我能够做到的:

首先安装Juypter(也可以使用pip3 ):

 sudo -H pip install --ignore-installed six --user --install jupiter 

然后你需要安装Python 2.7内核,否则你将只能使用python3的笔记本电脑。

 sudo -H python -m pip install --user --ignore-installed six --upgrade ipykernel python -m ipykernel install --user 

这可能对那些希望保持python2.7的Apple安装并希望使用python2.7和python3的Jupyter笔记本的人有用。

我刚刚使用easy_install安装

例如: $ sudo easy_install networkx