这篇文章主要讲述Python如何安装Numpy、Scipy、Matlotlib、Scikit-learn等库的过程及遇到的问题解决方法。最近安装这个真是一把泪啊,各种不兼容问题和报错,希望文章对你有所帮助吧!你可能遇到的问题包括:
ImportError: No module named sklearn 未安装sklearn包
ImportError: DLL load failed: 找不到指定的模块
ImportError: DLL load failed: The specified module could not be found
Microsoft Visual C++ 9.0 is required Unable to find vcvarsall.bat
Numpy Install RuntimeError: Broken toolchain: cannot link a simple C program
ImportError: numpy.core.multiarray failed to import
ImportError: cannot import name __check_build
ImportError: No module named matplotlib.pyplot
一. 安装过程
最早我是使用"pip install scikit-learn"命令安装的Scikit-Learn程序,并没有注意需要安装Numpy、Scipy、Matlotlib,然后在报错"No module named Numpy"后,我接着使用PIP或者下载exe程序安装相应的包,同时也不理解安装顺序和版本的重要性。其中最终都会报错" ImportError: DLL load failed: 找不到指定的模块",此时我的解决方法是:
错误:sklearn ImportError: DLL load failed: 找不到指定的模块
重点:安装python第三方库时总会出现各种兼容问题,应该是版本问题,版本需要一致。
第一步:卸载原始版本,包括Numpy、Scipy、Matlotlib、Scikit-Learn
pip uninstall scikit-learn
pip uninstall numpy
pip uninstall scipy
pip uninstall matplotlib
第二步:不使用"pip install package"或"easy_install package"安装,或者去百度\CSDN下载exe文件,而是去到官网下载相应版本。
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
http://www.lfd.uci.edu/~gohlke/pythonlibs/#matplotlib
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scikit-learn
安装过程中最重要的地方就是版本需要兼容。其中操作系统为64位,Python为2.7.8 64位,下载的四个whl文件如下,其中cp27表示CPython 2.7版本,cp34表示CPython 3.4,win_arm64指的是64位版本。
numpy-1.10.2-cp27-none-win_amd64.whl
scipy-0.16.1-cp27-none-win_amd64.whl
matplotlib-1.5.0-cp27-none-win_amd64.whl
scikit_learn-0.17-cp27-none-win_amd64.whl
PS:不推荐使用"pip install numpy"安装或下载如"numpy-MKL-1.8.0.win-amd64-py2.7.exe"类似文件,地址如:
http://sourceforge.net/projects/numpy/files/NumPy
http://sourceforge.net/projects/scipy/files/Scipy
第三步:去到Python安装Scripts目录下,再使用pip install xxx.whl安装,先装Numpy\Scipy\Matlotlib包,再安装Scikit-Learn。
其中我的python安装路径"G:\software\Program software\Python\python insert\Scripts",同时四个whl文件安装核心代码:
pip install G:\numpy+scipy+matplotlib\numpy-1.10.2-cp27-none-win_amd64.whl
pip install G:\numpy+scipy+matplotlib\scikit_learn-0.17-cp27-none-win_amd64.whl
C:\>G:
G:\>cd G:\software\Program software\Python\python insert\Scripts
G:\software\Program software\Python\python insert\Scripts>pip install G:\numpy+s
cipy+matplotlib\numpy-1.10.2-cp27-none-win_amd64.whl
Processing g:\numpy+scipy+matplotlib\numpy-1.10.2-cp27-none-win_amd64.whl
Installing collected packages: numpy
Successfully installed numpy-1.10.2
G:\software\Program software\Python\python insert\Scripts>pip install G:\numpy+s
cipy+matplotlib\matplotlib-1.5.0-cp27-none-win_amd64.whl
Installing collected packages: matplotlib
Successfully installed matplotlib-1.5.0
G:\software\Program software\Python\python insert\Scripts>pip install G:\numpy+s
cipy+matplotlib\scipy-0.16.1-cp27-none-win_amd64.whl
Processing g:\numpy+scipy+matplotlib\scipy-0.16.1-cp27-none-win_amd64.whl
Installing collected packages: scipy
Successfully installed scipy-0.16.1
G:\software\Program software\Python\python insert\Scripts>pip install G:\numpy+s
cipy+matplotlib\scikit_learn-0.17-cp27-none-win_amd64.whl
Processing g:\numpy+scipy+matplotlib\scikit_learn-0.17-cp27-none-win_amd64.whl
Installing collected packages: scikit-learn
Successfully installed scikit-learn-0.17
二、安装OpenCV
Python环境下的OpenCV安装
Python环境使用anaconda,在cmd中查看当前安装环境的版本号。易知,为Python3.6 64位。
在做版本选择时,我选择倒数第三个即 opencv_python-3.4.0-cp36-cp36m-win_amd64.whl
在此网站下载
我将其放置在E盘中,则使用命令:
pip install E:\other\opencv_python-3.4.0-cp36-cp36m-win_amd64.whl
在cmd下直接运行命令即可。
转载自:
[python] 安装numpy+scipy+matlotlib+scikit-learn及问题解决