Python 在 OSX 10.11 (El Capitan)(系统完整性保护)中安装 Scrapy 时出现“OSError: [Errno 1] Operation not allowed”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31900008/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"OSError: [Errno 1] Operation not permitted" when installing Scrapy in OSX 10.11 (El Capitan) (System Integrity Protection)
提问by Luis U.
I'm trying to install Scrapy Python framework in OSX 10.11 (El Capitan) via pip. The installation script downloads the required modules and at some point returns the following error:
我正在尝试通过 pip 在 OSX 10.11 (El Capitan) 中安装 Scrapy Python 框架。安装脚本下载所需的模块,并在某些时候返回以下错误:
OSError: [Errno 1] Operation not permitted: '/tmp/pip-nIfswi-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'
I've tried to deactivate the rootless feature in OSX 10.11 with the command:
我尝试使用以下命令停用 OSX 10.11 中的无根功能:
sudo nvram boot-args="rootless=0";sudo reboot
but I still get the same error when the machine reboots.
但是当机器重新启动时我仍然遇到同样的错误。
Any clue or idea from my fellow StackExchangers?
来自我的 StackExchangers 同事的任何线索或想法?
If it helps, the full script output is the following:
如果有帮助,完整的脚本输出如下:
sudo -s pip install scrapy
Collecting scrapy
Downloading Scrapy-1.0.2-py2-none-any.whl (290kB)
100% |████████████████████████████████| 290kB 345kB/s
Requirement already satisfied (use --upgrade to upgrade): cssselect>=0.9 in /Library/Python/2.7/site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): queuelib in /Library/Python/2.7/site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): pyOpenSSL in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from scrapy)
Collecting w3lib>=1.8.0 (from scrapy)
Downloading w3lib-1.12.0-py2.py3-none-any.whl
Collecting lxml (from scrapy)
Downloading lxml-3.4.4.tar.gz (3.5MB)
100% |████████████████████████████████| 3.5MB 112kB/s
Collecting Twisted>=10.0.0 (from scrapy)
Downloading Twisted-15.3.0.tar.bz2 (4.4MB)
100% |████████████████████████████████| 4.4MB 94kB/s
Collecting six>=1.5.2 (from scrapy)
Downloading six-1.9.0-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): zope.interface>=3.6.0 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from Twisted>=10.0.0->scrapy)
Requirement already satisfied (use --upgrade to upgrade): setuptools in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from zope.interface>=3.6.0->Twisted>=10.0.0->scrapy)
Installing collected packages: six, w3lib, lxml, Twisted, scrapy
Found existing installation: six 1.4.1
DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
Uninstalling six-1.4.1:
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/basecommand.py", line 223, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/commands/install.py", line 299, in run
root=options.root_path,
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_set.py", line 640, in install
requirement.uninstall(auto_confirm=True)
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_install.py", line 726, in uninstall
paths_to_remove.remove(auto_confirm)
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_uninstall.py", line 125, in remove
renames(path, new_path)
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/utils/__init__.py", line 314, in renames
shutil.move(old, new)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
copy2(src, real_dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
copystat(src, dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/tmp/pip-nIfswi-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'
采纳答案by Mario
I also think it's absolutely not necessary to start hacking OS X.
我也认为完全没有必要开始破解 OS X。
I was able to solve it doing a
我能够解决它做一个
brew install python
It seems that using the python / pip that comes with new El Capitan has some issues.
似乎使用新的 El Capitan 附带的 python/pip 有一些问题。
回答by rholmes
Warnings
警告
I would suggest very stronglyagainst modifying the system Python on Mac; there are numerous issues that can occur.
我强烈建议不要在 Mac 上修改系统 Python;可能会出现许多问题。
Your particular error shows that the installer has issues resolving the dependencies for Scrapy without impacting the current Python installation. The system uses Python for a number of essential tasks, so it's important to keep the system installation stableand as originally installed by Apple.
您的特定错误表明安装程序在解决 Scrapy 的依赖项而不影响当前 Python 安装时存在问题。系统使用 Python 执行许多基本任务,因此保持系统安装稳定且与 Apple 最初安装的一样非常重要。
I would also exhaust all other possibilitiesbefore bypassing built in security.
在绕过内置安全性之前,我还会用尽所有其他可能性。
Package Manager Solutions:
包管理器解决方案:
Please look into a Python virtualization tool such as virtualenvfirst; this will allow you to experiment safely.
请先研究一个Python虚拟化工具,例如virtualenv;这将使您能够安全地进行实验。
Another useful tool to use languages and software without conflicting with your Mac OS is Homebrew. Like MacPortsor Fink, Homebrew is a package manager for Mac, and is useful for safely trying lots of other languages and tools.
另一个使用语言和软件而不与 Mac OS 冲突的有用工具是Homebrew。与MacPorts或Fink一样,Homebrew 是 Mac 的包管理器,可用于安全地尝试许多其他语言和工具。
"Roll your own" Software Installs:
“自己动手”软件安装:
If you don't like the package manager approach, you could use the /usr/local
path or create an /opt/local
directory for installing an alternate Python installation and fix up your paths in your .bashrc
. Note that you'll have to enable root for these solutions.
如果您不喜欢包管理器方法,您可以使用该/usr/local
路径或创建一个/opt/local
目录来安装备用 Python 安装并在.bashrc
. 请注意,您必须为这些解决方案启用 root。
How to do it anyway:
无论如何怎么做:
If you absolutely must disable the security check(and I sincerely hope it's for something other than messing with the system languages and resources), you can disable it temporarily and re-enable it using some of the techniques in this post on how to Disable System Integrity-Protection.
如果你绝对必须禁用安全检查(我真诚地希望它不是为了弄乱系统语言和资源),你可以暂时禁用它并使用这篇关于如何禁用系统的文章中的一些技术重新启用它完整性保护。
回答by Ergun Ozyurt
You should disable "System Integrity Protection" which is a new feature in El Capitan.
您应该禁用“系统完整性保护”,这是 El Capitan 中的一项新功能。
First, you should run the command for rootless config on your terminal
首先,您应该在终端上运行无根配置命令
# nvram boot-args="rootless=0"
# reboot
Then, you should run the command below on recovery partition's terminal (Recovery OS)
然后,您应该在恢复分区的终端(恢复操作系统)上运行以下命令
# csrutil disable
# reboot
I've just solved my problem like that. I'm not sure that the first part is necessary. Try as you like.
我刚刚解决了我的问题。我不确定第一部分是否必要。随心所欲地尝试。
--WARNING
- 警告
You should enable SIP again after everything works;
一切正常后,您应该再次启用 SIP;
Simply reboot again into Recovery Mode and run in terminal
只需再次重启进入恢复模式并在终端中运行
# csrutil enable
csrutil: Configuring System Integrity Protection
csrutil:配置系统完整性保护
回答by Sath
回答by Sandeep
Restart Mac -> hold down "Command + R" after the startup chime -> Opens OS X Utilities -> Open Terminal and type "csrutil disable" -> Reboot OS X -> Open Terminal and check "csrutil status"
重新启动 Mac -> 在启动提示音后按住“Command + R” -> 打开 OS X 实用程序 -> 打开终端并输入“csrutil disable” -> 重新启动 OS X -> 打开终端并检查“csrutil status”
回答by jimmyzhouj
- -- close SIP(system Integrity Protection) -- then reboot, use command +R to enter debug mode, then select terminal: csrutil disable reboot
- -- 关闭SIP(system Integrity Protection) -- 然后重启,使用命令+R进入调试模式,然后选择终端:csrutil disable reboot
2.
2.
sudo C_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2 :/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2/libxml :/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include pip install scrapy --ignore-installed six
sudo C_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2 :/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX .platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2/libxml :/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/包括 pip install scrapy --ignore-installed 六
3. -- then remove old six, install it again sudo rm -rf /Library/Python/2.7/site-packages/six* sudo rm -rf /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six* sudo pip install six
3. -- 然后删除旧的六个,重新安装 sudo rm -rf /Library/Python/2.7/site-packages/six* sudo rm -rf /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/ lib/python/six* sudo pip install 6
4. -- then set it back csrutil enable reboot
4. -- 然后将其设置回 csrutil enable reboot
-- crappy works now
- 现在糟糕的作品
回答by Evelin Ponce
I tried to install AWS via pip in El Capitan but this error appear
我尝试通过 El Capitan 中的 pip 安装 AWS,但出现此错误
OSError: [Errno 1] Operation not permitted: '/var/folders/wm/jhnj0g_s16gb36y8kwvrgm7h0000gp/T/pip-wTnb_D-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'
OSError: [Errno 1] 不允许操作: '/var/folders/wm/jhnj0g_s16gb36y8kwvrgm7h0000gp/T/pip-wTnb_D-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/python/Extras/lib/ 1.4.1-py2.7.egg-info'
I found the answer here
我在这里找到了答案
sudo -H pip install awscli --upgrade --ignore-installed six
It works for me :)
这个对我有用 :)
回答by Roger
This did the trick for me:
这对我有用:
sudo pip install scrapy --ignore-installed six
回答by Miss Haha
This did the trick for me.
这对我有用。
sudo pip install --ignore-installed scrapy
sudo pip install --ignore-installed scrapy
回答by dietbacon
As the other answers said, it's because of the new System Integrity Protection, but I believe the other answers are overcomplicated.
正如其他答案所说,这是因为新的系统完整性保护,但我相信其他答案过于复杂。
If you're only gonna use that package in the current user, you should be able to install it just fine, without the need to disable the SIP, by using the --user
flag. Like this:
如果您只想在当前用户中使用该软件包,您应该可以通过使用该--user
标志来安装它,而无需禁用 SIP 。像这样:
sudo pip install --user packagename