安装numpy+scipy+matlotlib+scikit-learn及问题解决
2017-02-22 16:30
351 查看
一. 安装过程
最早我是使用"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[/code]
安装过程中最重要的地方就是版本需要兼容。其中操作系统为64位,Python为2.7.8
64位,下载的四个whl文件如下,其中cp27表示CPython 2.7版本,cp34表示CPython 3.4,win_arm64指的是64位版本。
上面的网址速度感人,分享一下我目前用的文件:
链接:http://pan.baidu.com/s/1eSmRKTc 密码:4vjl
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搞了这么半天,为什么要装这些呢?给几个用例验证它的正确安装和强大吧!
二. 测试运行环境
Scikit-Learn是基于python的机器学习模块,基于BSD开源许可。Scikit-learn的基本功能主要被分为六个部分,分类,回归,聚类,数据降维,模型选择,数据预处理,具体可以参考官方网站上的文档。
NumPy(Numeric Python)系统是Python的一种开源的数值计算扩展,一个用python实现的科学计算包。它提供了许多高级的数值编程工具,如:矩阵数据类型、矢量处理,以及精密的运算库。专为进行严格的数字处理而产生。
内容包括:1、一个强大的N维数组对象Array;2、比较成熟的(广播)函数库;3、用于整合C/C++和Fortran代码的工具包;4、实用的线性代数、傅里叶变换和随机数生成函数。numpy和稀疏矩阵运算包scipy配合使用更加方便。
SciPy (pronounced "Sigh Pie") 是一个开源的数学、科学和工程计算包。它是一款方便、易于使用、专为科学和工程设计的Python工具包,包括统计、优化、整合、线性代数模块、傅里叶变换、信号和图像处理、常微分方程求解器等等。
Matplotlib是一个Python的图形框架,类似于MATLAB和R语言。它是python最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地进行制图。而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中。
第一个代码:斜线坐标,测试matplotlibimport matplotlib import numpy import scipy import matplotlib.pyplot as plt plt.plot([1,2,3]) plt.ylabel('some numbers') plt.show()
第二个代码:桃心程序,测试numpy和matplotlibimport numpy as np import matplotlib.pyplot as plt X = np.arange(-5.0, 5.0, 0.1) Y = np.arange(-5.0, 5.0, 0.1) x, y = np.meshgrid(X, Y) f = 17 * x ** 2 - 16 * np.abs(x) * y + 17 * y ** 2 - 225 fig = plt.figure() cs = plt.contour(x, y, f, 0, colors = 'r') plt.show()
第三个程序:显示Matplotlib强大绘图交互功能import numpy as np import matplotlib.pyplot as plt N = 5 menMeans = (20, 35, 30, 35, 27) menStd = (2, 3, 4, 1, 2) ind = np.arange(N) # the x locations for the groups width = 0.35 # the width of the bars fig, ax = plt.subplots() rects1 = ax.bar(ind, menMeans, width, color='r', yerr=menStd) womenMeans = (25, 32, 34, 20, 25) womenStd = (3, 5, 2, 3, 3) rects2 = ax.bar(ind+width, womenMeans, width, color='y', yerr=womenStd) # add some ax.set_ylabel('Scores') ax.set_title('Scores by group and gender') ax.set_xticks(ind+width) ax.set_xticklabels( ('G1', 'G2', 'G3', 'G4', 'G5') ) ax.legend( (rects1[0], rects2[0]), ('Men', 'Women') ) def autolabel(rects): # attach some text labels for rect in rects: height = rect.get_height() ax.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%d'%int(height), ha='center', va='bottom') autolabel(rects1) autolabel(rects2) plt.show()
第四个代码:矩阵数据集,测试sklearnfrom sklearn import datasets iris = datasets.load_iris() digits = datasets.load_digits() print digits.data
这里虽然讲解几个安装时遇到的其他错误及解决方法,但作者更推荐上面的安装步骤。
三. 其他错误解决方法
在这之前,我反复的安装、卸载、升级包,其中遇到了各种错误,改了又改,百度了又谷歌。常见PIP用法如下:* pip install numpy --安装包numpy * pip uninstall numpy --卸载包numpy * pip show --files PackageName --查看已安装包 * pip list outdated --查看待更新包信息 * pip install --upgrade numpy --升级包 * pip install -U PackageName --升级包 * pip search PackageName --搜索包 * pip help --显示帮助信息
ImportError: numpy.core.multiarray failed to import
python安装numpy时出现的错误,这个通过stackoverflow和百度也是需要python版本与numpy版本一致,解决的方法包括"pip install -U numpy"升级或下载指定版本"pip install numpy==1.8"。但这显然还涉及到更多的包,没有前面的卸载下载安装统一版本的whl靠谱。
Microsoft Visual C++ 9.0 is required(unable to find vcvarsall.bat)
因为Numpy内部矩阵运算是用C语言实现的,所以需要安装编译工具,这和电脑安装的VC++或VS2012有关,解决方法:如果已安装Visual Studio则添加环境变量VS90COMNTOOLS即可,不同的VS版本对应不同的环境变量值:
Visual Studio 2010 (VS10)设置 VS90COMNTOOLS=%VS100COMNTOOLS%
Visual Studio 2012 (VS11)设置 VS90COMNTOOLS=%VS110COMNTOOLS%
Visual Studio 2013 (VS12)设置 VS90COMNTOOLS=%VS120COMNTOOLS%
但是这并没有解决,另一种方法是下载Micorsoft Visual C++ Compiler for Python 2.7的包,链接:http://pan.baidu.com/s/1kU8MceF 密码:eter 。
PS:这些问题基本解决方法使用pip升级、版本一致、重新下载相关版本exe文件再安装。
相关文章推荐
- [python] 安装numpy+scipy+matlotlib+scikit-learn及问题解决
- [python] 安装numpy+scipy+matlotlib+scikit-learn及问题解决
- [python] 安装numpy+scipy+matlotlib+scikit-learn及问题解决
- [python] 安装numpy+scipy+matlotlib+scikit-learn及问题解决
- [python] 安装numpy+scipy+matlotlib+scikit-learn及问题解决
- [python] 安装numpy+scipy+matlotlib+scikit-learn及问题解决
- 安装numpy+scipy+matlotlib+scikit-learn及问题解决
- [python] 安装numpy+scipy+matlotlib+scikit-learn及问题解决
- 机器学习的相关模块安装:pandas,numpy, scipy,scikit_learn(sklearn), matplotlib在winows系统下的安装问题
- 安装Numpy,scipy,matlotlib,scikit_learn
- Windows环境下实现Numpy、Scipy、Matlotlib、Scikit-learn的安装
- windows下安装python numpy+scipy+matlotlib+scikit-learn等流行库
- 在Ubuntu Linux 安装Python第三方库:NumPy,SciPy,Matplotlib, Scikit-Learn,Theao等
- win64下安装numpy-scipy-matplotlib-scikit-learn
- 安装基于Python3 的NumPy, SciPy, matplotlib和Scikit-Learn
- Numpy\Scipy\Matlotlib\Scikit-Learn
- linux下python的机器学习包scikit-learn(包含numpy、scipy等)安装
- 64位32位windows7安装python34和python27,numpy,scipy,matplotlib,scikit-learn等第三方模块
- Python安装numpy,matplotlib,scikit_learn遇到的问题大汇总
- CentOS 6.5下安装NumPy、SciPy、Scikit-Learn