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

时间:2015-10-08 00:34:20

标签: pip ipython failed-installation osx-elcapitan

当我跑步时:

sudo pip install ipython

我收到以下错误

  

OSError:[Errno:1]不允许操作:'/ System / Library / Frame /Python.framework / Version / 7.7 / share'

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

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

sudo pip install --user python

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

16 个答案:

答案 0 :(得分:198)

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

如果有任何教程说明你应该sudo pip,那么请提交一个针对此软件包的错误。作者正在教育Python社区,因为时间证明sudo pip是一种破碎的做法。

OSX El Capitan introduced a mechanisms to prevent damaging the operating system files/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

更多信息

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

答案 1 :(得分:25)

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

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

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

答案 2 :(得分:19)

你应该重新安装Python:

brew reinstall python

要获得啤酒,请参阅brew homepage

答案 3 :(得分:16)

pip install --ignore-installed six

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

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

答案 4 :(得分:11)

使用pip3 install <package>代替pip解决了权限问题。

答案 5 :(得分:10)

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

brew doctor 

并修复警告,您应该能够继续进行pip安装。

答案 6 :(得分: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'

这里我使用--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 

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

答案 7 :(得分:8)

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
  5. 详细

    由于macOS 10.11 El Capitan中的新系统完整性保护,您不能再sudo pip install。我们不会在这里讨论它的优点。

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

    以下是我如何在我的某个系统上解决问题的记录。我把它包括在内而不仅仅是为我工作的$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>
    

答案 8 :(得分: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包位置)更高,所以即使你设法安装某些软件包的较新版本,旧的仍然加载,打破一些依赖。
  4. https://apple.stackexchange.com/a/223163/143849有所有这些的解决方法。但您可能最好通过标准的Python安装程序,Homebrew或Anaconda安装自己的Python版本。

答案 9 :(得分:4)

我完全赞同Mikko,但如果你仍然想这样做,那就是这样:

  • 重新启动恢复模式(按住cmd + R)
  • 从公用事业公开终端
  • 使用命令csrutil disable

答案 10 :(得分:4)

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

pip install google-api-python-client --upgrade --ignore-installed six

pip install --ignore-installed six

答案 11 :(得分:1)

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

brew install numpy

它安装了python3,但它仍然可以工作并将其设置为2.7。

答案 12 :(得分:0)

和你一样,我遇到了同样的问题。我正在运行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笔记本的人来说,这可能很有用。

答案 13 :(得分:0)

pip install ipython失败后,这对我有用:

SF55M:~ 278$ sudo easy_install ipython
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.

In [1]:
Do you really want to exit ([y]/n)?
SF55M:~ 278$

答案 14 :(得分:0)

它对我有用,因为我同时安装了python 2和3。

brew reinstall python@2

答案 15 :(得分:-2)

我刚刚使用easy_install

安装了它

例如: $ sudo easy_install networkx