mac下不能卸载和升级numpy的解决办法

之前要换电脑,听同事的建议,买了个Mac book pro,原因是说苹果对程序员比较友好。可是,前不久在使用gensim的时候(import gensim),总是报错说ValueError: numpy.dtype has the wrong size, try recompiling,在网上查了相关帖子,大约就是numpy的版本和gensim要求的版本不同,所以才报错。  

然后我就想着,那就pip install -U 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 renamesshutil.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'。 

然后我发现我忘了加sudo,于是试了一下sudo pip install -U numpy,结果还是不管用,报同样的错误。又去网上查,有人说是System Integrity Protection的问题,解决的办法是关闭保护SIP。刚才找了半天,没找到帮助我解决问题的那个帖子,所以我就不引用他的文章了。具体操作如下:

1. 重启电脑,电脑启动的时候按住command+R;

2. 等画面上显示苹果logo的时候之后,你会看到「OS X 工具程式」的窗口,选择终端(注意,这里选择的时候要把键盘按下去,而不是在键盘上轻击,我一开始就是轻击,然后发现电脑根本没有反应,还以为电脑坏了,原谅我也没用苹果多久);

3. 然后终端就打开了,你直接输入csrutil disable,输完之后重启;

电脑重启之后,再重新执行sudo pip install -U numpy,我这边结果如下:

The directory '/Users/lyj/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/lyj/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting numpy
  Downloading 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.whl (3.7MB)
    100% |████████████████████████████████| 3.7MB 21kB/s
Installing 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:
      Successfully uninstalled numpy-1.8.0rc1
Successfully installed numpy-1.10.2

更新成功了,为了验证是否解决了我之前的问题,我又打开python,然后import gensim,这次不报错了,终于解决了我的问题。

第一次在CSDN上写文章,之前都是看别人分享经验,为了不让其他人和我一样浪费这么多时间,我决定也分享一下自己的经验,下面给出两个参考的连接:

1. 为什么要把SIP关掉 http://osxdaily.com/2015/10/05/disable-rootless-system-integrity-protection-mac-os-x/

2. 重启电脑 https://support.apple.com/zh-tw/HT201314


展开阅读全文

没有更多推荐了,返回首页