您的位置:首页 > 编程语言 > Python开发

Mac系统10.11及以上升级numpy、scipy等python包报错解决方案

2016-07-09 17:30 363 查看
发现一个问题。Mac系统自带的python无法更新第三方包numpy包,错误如下:

Collecting numpy
Using cached numpy-1.10.2-cp27-none-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whlInstalling
collected packages: numpy
Found existing installation: numpy 1.8.0rc1
DEPRECATION: Uninstalling a distutils installed project (numpy) 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 numpy-1.8.0rc1:Exception:Traceback
(most recent call last):
File "/Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg/pip/basecommand.py", line 211, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg/pip/commands/install.py", line 311, in run
root=options.root_path,
File "/Library/Python/2.7/site-packages/pip-7.1.2-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.2-py2.7.egg/pip/req/req_install.py", line 716, in uninstall
paths_to_remove.remove(auto_confirm)
File "/Library/Python/2.7/site-packages/pip-7.1.2-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.2-py2.7.egg/pip/utils/__init__.py",
line 315, 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: '/var/folders/5n/vbm997m56xg3kw67y6bccn2m0000gn/T/pip-4tcBsd-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy-1.8.0rc1-py2.7.egg-info'


使用pip 重新安装 numpy 包

pip install -U numpy

依然报错,错误输出的内容和上面的一致。

冷静下来后重新看了一些错,Operation not permitted 没有操作权限。奇怪了,系统在10.9和10.10的时候都没有出现这种情况,难道是苹果自己搞的鬼?

自己无法解决,只好求助于“度娘“ 和谷歌,不懈努力后还真的发现了问题。

经历了XCode编译器代码被注入的事件后,这次 Mac OS X El Capitan系统的升级,启用了更高的安全性保护机制:系统完整性保护System Integrity Protection (SIP)。简单来讲就是更加强制性的保护系统相关的文件夹。开发者不能直接操作相关的文件内容。

苹果官方的解释

System Integrity Protection is a security technology in OS X El Capitan that’s designed to help prevent potentially malicious software from modifying protected files and folders on your Mac.

In OS X, the “root” user account previously had no permission restrictions and could access any system folder or application on your Mac. Software gained root-level access when you entered your administrator name and password to install it and could then modify or overwrite any system file or application.

System Integrity Protection restricts the root account and limits the actions that the root user can perform on protected parts of OS X.

Paths and applications protected by System Integrity Protection include:

/System

/usr

/bin

/sbin

Apps that are pre-installed with OS X

Paths and applications that third-party apps and installers can write to include:

/Applications

/Library

/usr/local

System Integrity Protection is designed to allow modifications of these protected parts only by processes that are signed by Apple and have special entitlements to write to system files, like Apple software updates and Apple installers.

Apps that you download from the Mac App Store already work with System Integrity Protection. Other third-party software that conflicts with System Integrity Protection might be set aside when you upgrade to OS X El Capitan.

System Integrity Protection also helps prevent software from changing your startup volume. To boot your Mac from a different volume, you can use the Startup Disk pane in System Preferences or you can hold down the Option key while you reboot, and select a volume from the list.

Information about products not manufactured by Apple, or independent websites not controlled or tested by Apple, is provided without recommendation or endorsement. Apple assumes no responsibility with regard to the selection, performance, or use of third-party websites or products. Apple makes no representations regarding third-party website accuracy or reliability. Risks are inherent in the use of the Internet. Contact the vendor for additional information. Other company and product names may be trademarks of their respective owners.

Last Modified: Oct 2, 2015

来源: https://support.apple.com/en-us/HT204899

找到问题的原因就可以解决相关的问题了,解决问题的方法就是关闭Mac系统的“SIP“。

具体的操作步骤,引用国外的一个牛人给出的方法:

How to turn off System Integrity Protection in El Capitan

Click the  menu.

Select Restart…

Hold down command-R to boot into the Recovery System.

Click the Utilities menu and select Terminal.

Type csrutil disable and press return .

Close the Terminal app.

Click the  menu and select Restart… .

来源:http://www.imore.com/el-capitan-system-integrity-protection-helps-keep-malware-away?utm_source=tuicool&utm_medium=referral

点击Mac电脑的苹果图标

选择 重新启动

按住 command+R,直到进入还原模式

选择实用工具,然后点击 终端

输入 csrutil disable 按下回车

重启电脑

这样就将“SIP“关闭了。

然后我们使用 pip 安装升级numpy、scipy等相关的包。

问题是解决了,但是如果到这里就认为已经万事大吉了,其实是大错特错了。苹果官方之所以设置“SIP“主要是考虑到系统的安全性问题。所以,我们最好还是将“SIP“打开。打开的方式如下:

1. 点击Mac电脑的苹果图标

2. 选择 重新启动

3. 按住 command+R,直到进入还原模式

4. 选择实用工具,然后点击 终端

5. 输入 csrutil enable 按下回车

6. 重启电脑

万事大吉,收工睡觉!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python numpy mac