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

發佈了27 篇原創文章 · 獲贊 30 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章