pip install pytest on Mac (EI Capitan 10.11.6)

升级了Mac 系统后发现用pip安装pytest出现下面链接中的问题,解决方法是在install时候加上--user选项:

1. 切到home directory: cd ~

2. install pytest:  pip install pytest --user

Collecting pytest

  Using cached pytest-3.2.2-py2.py3-none-any.whl

Requirement already satisfied: setuptools in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from pytest)

Collecting py>=1.4.33 (from pytest)

  Using cached py-1.4.34-py2.py3-none-any.whl

Installing collected packages: py, pytest

Successfully installed py-1.4.34 pytest-3.2.2

原文链接如下:

http://marcelog.github.io/articles/mac_osx_python_pip_install_operation_not_permitted.html

PIP Install on Mac: Operation Not Permitted

 

If you are trying to do a

pip install <package>

on a Mac and get an error like

Could not create /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7: Operation not permitted

You hit an internal protection called System Integrity Protection built-in OS X El Capitan and laterthat, among other things, protects some paths of your root filesystem in a way that not even the user root can write to them.

And your are not alone, this "issue" has hit a lot of users of different open source Python packages, as one can see in some GitHub Issues.

In the specific case of using PIP to install Python packages, you can overcome this by installing everything into your own home directory with the --user flag, like:

pip install <package> --user

This flag is documented in the "Installing to the User Site" section of the "Python Packaging User Guide", and there is more in depth description of the process in the "User Installs" section of the "PIP User Guide"

For more information on SIP, I recommend you start with this great article about OSX El Capitan System Integrity Protection (or SI

原文地址:https://www.cnblogs.com/littledrop/p/7593996.html