Cannot uninstall 'numpy'問題

今天不知道做了什麼騷操作,導致import cv2的時候突然報錯:

ImportError: numpy.core.multiarray failed to import

應該是numpy安裝出錯了,所以執行pip uninstall numpy,貌似成功卸載了,然後重新pip install numpy發現還是不行,會報錯:

Found existing installation: numpy 1.7.1

這個1.7.1應該就是上面說的騷操作的結果。後面嘗試了什麼pip install -U numpy會報錯:

Found existing installation: numpy 1.7.1
ERROR: Cannot uninstall 'numpy'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

或者嘗試:pip install --ignore-installed numpy,可以正常安裝numpy,但是在import numpy的時候會報錯:

ImportError: Something is wrong with the numpy installation. While importing we detected an older version of numpy in ['/usr/lib64/python2.7/site-packages/numpy']. One method of fixing this is to repeatedly uninstall numpy until none is found, then reinstall this version.

還是版本問題,最後孤注一擲的解決辦法,找到python包的位置,例如centos是/usr/lib64/python2.7/site-packages/下,雖然前面卸載了numpy,進入文件夾後還是能發現numpy文件夾的出現,然後刪除看到的numpy相關文件,然後再次重新安裝numpy,此時恢復正常了!!!

ps:由於opencv依賴numpy,而且不同版本的opencv對numpy要求可能也不同,所以一定要安裝對應opencv版本的numpy,否則在import cv2的時候會報錯。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章