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的时候会报错。

你可能感兴趣的:(python2.7,python,opencv)