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

Mil*_*d M 126 pip failed-installation ipython osx-elcapitan

当我跑:

sudo pip install ipython
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

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

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

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

sudo pip install --user python
Run Code Online (Sandbox Code Playgroud)

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

Mik*_*maa 203

说明说明sudo pip install本身就是错误的.

如果有任何教程说你应该做,sudo pip那么请提交一个错误来反对这个包.作者正在sudo pip消除Python社区的教育,因为时间已被证明是一种破碎的做法.

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

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

例:

cd ~  # Go to home directory
virtualenv my-venv
source my-venv/bin/activate
pip install IPython
Run Code Online (Sandbox Code Playgroud)

更多信息

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

  • 尽管如此,这并没有解决原始问题.我正在尝试安装IPython并使其全局可用(对于我机器上的所有用户),并且virtualenv和`pip install --user IPython`都没有帮助.而且,`pip install --user IPython`无法将`ipython`命令放在`$ PATH`中(至少在我的机器上). (26认同)
  • 如果不需要virtualenv并且您想要全局(例如/Library/Python/2.7/site-packages)安装模块,请使用`easy_install`尝试我的解决方案http://stackoverflow.com/a/33463702/3078330 (5认同)
  • 你对"sudo pip"糟糕的观点有所引用吗("因为时间已经证明sudo pip是一种破碎的做法")?我没有在你给出的引文中看到任何关于sudo的讨论,教程列出了创建virtualenvs作为'pip install virtualenv'的第一步,这似乎创建了一个循环依赖,试图遵循你的建议. (3认同)
  • 你教我,也节省了我的时间.非常感谢我停止使用sudo,一切正常!很好的答案. (3认同)

sma*_*8dd 24

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

我不知道为什么,但是pip和easy_install使用不同的安装位置,easy_install选择了正确的安装位置.

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


dav*_*ler 19

你应该重新安装Python:

brew reinstall python
Run Code Online (Sandbox Code Playgroud)

要获得啤酒,请参阅brew主页.


小智 15

pip install --ignore-installed six

这将完成工作,然后您可以尝试第一个命令.

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

  • 不,由于缺乏权限,这将无法完成工作. (2认同)

小智 11

用来pip3 install <package>代替与解决权限问题pip.

  • 仅供参考,因为`pip3`使用Python 3,它通常由用户安装.另一方面,Python 2(2.7)随macOS一起提供,并且受到最高评级答案的解释. (10认同)

Goi*_*Way 10

同样的错误

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'
Run Code Online (Sandbox Code Playgroud)

在这里我使用--user没有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 
Run Code Online (Sandbox Code Playgroud)

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

  • 您不应该将`sudo`与`--user`一起使用。--user所做的是安装到〜/ Library中,而不是安装在/ Library中。您不必使用sudo来安装。但是,使用sudo安装后,目录和文件全部由root拥有。然后您必须使用`sudo`对他们执行其他任何操作。反过来,这将要求您将sudo用作其他您不应该使用的东西。这样,即使是诚实的错误,也可以从引发错误到破坏数据。 (3认同)

Bru*_*sky 10

TL; DR $ PATH修复

  1. 使用pip install --user package_name安装包,应包括CLI可执行文件.
  2. 启动一个python shell和 import package_name
  3. 查找lib/python/...输出中出现的位置并将其全部替换bin
  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>
Run Code Online (Sandbox Code Playgroud)


apa*_*ana 9

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

brew doctor 
Run Code Online (Sandbox Code Playgroud)

并修复警告,你应该能够继续你的pip安装.


Mat*_*ipp 6

由于以下几个原因,很难在El Capitan工作:

  1. OS X没有正确设置一些distutils变量,所以pip尝试在下面的位置安装辅助文件/System/Library/.El Capitan阻止了这个,这是你遇到的错误.
  2. OS X包含许多过时的软件包/System/Library/.pip经常想升级这些但不能在El Capitan上升级.
  3. OS X /System/Library/在python搜索顺序中的位置高于/Library/Python/2.7/site-packages(系统范围的python包位置),因此即使您设法安装某些包的较新版本,旧的仍会加载,从而破坏了一些依赖关系.

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