OSX El Capitan: sudo pip install OSError: [Errno:

2019-01-02 19:45发布

When I run:

sudo pip install ipython

I get the following error

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.

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

sudo pip install --user python

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

15条回答
无与为乐者.
2楼-- · 2019-01-02 19:57

I have python2.7 installed via brew and the following solved my problem

brew install numpy

It installs python3, but it still works and sets it up for 2.7 as well.

查看更多
零度萤火
3楼-- · 2019-01-02 20:01

Instructions telling sudo pip install are inherently wrong.

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 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.

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.

Example:

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

More info

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.

查看更多
梦该遗忘
4楼-- · 2019-01-02 20:02

I guess you have some conflict with other package. For me it was six. So you need to use a command like this:

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

or

pip install --ignore-installed six

查看更多
倾城一夜雪
5楼-- · 2019-01-02 20:06

I fully agree with Mikko, but if you still want to do it, here is the way:

  • Restart in recovery mode (Hold cmd + R)
  • Open terminal from utilities
  • Use the command csrutil disable
查看更多
美炸的是我
6楼-- · 2019-01-02 20:08

Like you I had the same problem. I'm running El Capitan and trying to install Juypter with python2.7 Here's how I was able to do it:

First install Juypter (would work also with pip3):

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

Then you need install the python 2.7 kernel, otherwise you'll only be able to use python3 for the notebook.

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

This may be useful for those who wish to keep the Apple installation of python2.7 and want to use the Jupyter notebook with both python2.7 and python3.

查看更多
何处买醉
7楼-- · 2019-01-02 20:08

I just installed it using easy_install

Eg: $ sudo easy_install networkx

查看更多
登录 后发表回答