购物网站建设费用,优化大师免费下载,网站设计包括,微信小程序登录流程这篇文章主要讲述Python如何安装Numpy、Scipy、Matlotlib、Scikit-learn等库的过程及遇到的问题解决方法。最近安装这个真是一把泪啊#xff0c;各种不兼容问题和报错#xff0c;希望文章对你有所帮助吧#xff01;你可能遇到的问题包括#xff1a; ImportError: N…这篇文章主要讲述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第三方库时总会出现各种兼容问题应该是版本问题版本需要一致。 下载http://download.csdn.net/detail/eastmount/9366117第一步卸载原始版本包括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.4win_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类似文件地址如 Numerical Python - Browse /NumPy at SourceForge.net SciPy: Scientific Library for Python - Browse Files at SourceForge.net 第三步去到Python安装Scripts目录下再使用pip install xxx.whl安装先装Numpy\Scipy\Matlotlib包再安装Scikit-Learn。其中我的python安装路径G:\software\Program software\Python\python insert\Scripts同时四个whl文件安装核心代码 pip install G:\numpyscipymatplotlib\numpy-1.10.2-cp27-none-win_amd64.whl pip install G:\numpyscipymatplotlib\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\Scriptspip install G:\numpys
cipymatplotlib\numpy-1.10.2-cp27-none-win_amd64.whl
Processing g:\numpyscipymatplotlib\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\Scriptspip install G:\numpys
cipymatplotlib\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\Scriptspip install G:\numpys
cipymatplotlib\scipy-0.16.1-cp27-none-win_amd64.whl
Processing g:\numpyscipymatplotlib\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\Scriptspip install G:\numpys
cipymatplotlib\scikit_learn-0.17-cp27-none-win_amd64.whl
Processing g:\numpyscipymatplotlib\scikit_learn-0.17-cp27-none-win_amd64.whl
Installing collected packages: scikit-learn
Successfully installed scikit-learn-0.17 第四步此时配置完成关键是Python64位版本兼容问题和Scripts目录。最后用北邮论坛一个神人的回复结束这个安装过程“傻孩子用套件啊给你介绍一个Anaconda或winpython。只能帮你到这里了 ” 二. 测试运行环境
搞了这么半天为什么要装这些呢给几个用例验证它的正确安装和强大吧Scikit-Learn是基于python的机器学习模块基于BSD开源许可。Scikit-learn的基本功能主要被分为六个部分分类回归聚类数据降维模型选择数据预处理具体可以参考官方网站上的文档。NumPyNumeric Python系统是Python的一种开源的数值计算扩展一个用python实现的科学计算包。它提供了许多高级的数值编程工具如矩阵数据类型、矢量处理以及精密的运算库。专为进行严格的数字处理而产生。 内容包括1、一个强大的N维数组对象Array2、比较成熟的广播函数库3、用于整合C/C和Fortran代码的工具包4、实用的线性代数、傅里叶变换和随机数生成函数。numpy和稀疏矩阵运算包scipy配合使用更加方便。SciPy (pronounced Sigh Pie) 是一个开源的数学、科学和工程计算包。它是一款方便、易于使用、专为科学和工程设计的Python工具包包括统计、优化、整合、线性代数模块、傅里叶变换、信号和图像处理、常微分方程求解器等等。Matplotlib是一个Python的图形框架类似于MATLAB和R语言。它是python最著名的绘图库它提供了一整套和matlab相似的命令API十分适合交互式地进行制图。而且也可以方便地将它作为绘图控件嵌入GUI应用程序中。第一个代码斜线坐标测试matplotlib
import matplotlib
import numpy
import scipy
import matplotlib.pyplot as plt plt.plot([1,2,3])
plt.ylabel(some numbers)
plt.show() 运行结果 第二个代码桃心程序测试numpy和matplotlib代码参考Windows 下 Python easy_install 的安装 - KingsLanding
import 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强大绘图交互功能代码参考Python-Matplotlib安装及简单使用 - bery
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, colorr, yerrmenStd) womenMeans (25, 32, 34, 20, 25)
womenStd (3, 5, 2, 3, 3)
rects2 ax.bar(indwidth, womenMeans, width, colory, yerrwomenStd) # add some
ax.set_ylabel(Scores)
ax.set_title(Scores by group and gender)
ax.set_xticks(indwidth)
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), hacenter, vabottom) autolabel(rects1)
autolabel(rects2) plt.show()
运行结果 PS如果设置legend没有显示比例图标则参考下面代码
[python] view plain copy # codingutf-8 import numpy as np import matplotlib import scipy import matplotlib.pyplot as plt #设置legend: http://bbs.byr.cn/#!article/Python/7705 #mark样式: http://www.360doc.com/content/14/1026/02/9482_419859060.shtml #国家 融合特征值 x1 [10, 20, 50, 100, 150, 200, 300] y1 [0.615, 0.635, 0.67, 0.745, 0.87, 0.975, 0.49] #动物 x2 [10, 20, 50, 70, 90, 100, 120, 150] y2 [0.77, 0.62, 0.77, 0.86, 0.87, 0.97, 0.77, 0.47] #人物 x3 [10, 20, 50, 70, 90, 100, 120, 150] y3 [0.86, 0.86, 0.92, 0.94, 0.97, 0.97, 0.76, 0.46] #国家 x4 [10, 20, 50, 70, 90, 100, 120, 150] y4 [0.86, 0.85, 0.87, 0.88, 0.95, 1.0, 0.8, 0.49] plt.title(Entity alignment result) plt.xlabel(The number of class clusters) plt.ylabel(Similar entity proportion) plot1, plt.plot(x1, y1, -p, linewidth2) plot2, plt.plot(x2, y2, -*, linewidth2) plot3, plt.plot(x3, y3, -h, linewidth2) plot4, plt.plot(x4, y4, -d, linewidth2) plt.xlim(0, 300) plt.ylim(0.4, 1.0) #plot返回的不是matplotlib对象本身,而是一个列表,加个逗号之后就把matplotlib对象从列表里面提取出来 plt.legend( (plot1,plot2,plot3,plot4), (Spot, Animal, People, Country), fontsize10) plt.show() 输出如下图所示 第四个代码矩阵数据集测试sklearn
from sklearn import datasets
iris datasets.load_iris()
digits datasets.load_digits()
print digits.data
运行结果 第五个代码计算TF-IDF词语权重测试scikit-learn数据分析参考代码python scikit-learn计算tf-idf词语权重_python 分词权重_liuxuejiang158的博客-CSDN博客
# coding:utf-8
__author__ liuxuejiang
import jieba
import jieba.posseg as pseg
import os
import sys
from sklearn import feature_extraction
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.feature_extraction.text import CountVectorizer if __name__ __main__: corpus[我 来到 北京 清华大学, #第一类文本切词后的结果 词之间以空格隔开 他 来到 了 网易 杭研 大厦, #第二类文本的切词结果 小明 硕士 毕业 与 中国 科学院, #第三类文本的切词结果 我 爱 北京 天安门] #第四类文本的切词结果 #该类会将文本中的词语转换为词频矩阵矩阵元素a[i][j] 表示j词在i类文本下的词频 vectorizerCountVectorizer() #该类会统计每个词语的tf-idf权值 transformerTfidfTransformer() #第一个fit_transform是计算tf-idf第二个fit_transform是将文本转为词频矩阵 tfidftransformer.fit_transform(vectorizer.fit_transform(corpus)) #获取词袋模型中的所有词语 wordvectorizer.get_feature_names() #将tf-idf矩阵抽取出来元素a[i][j]表示j词在i类文本中的tf-idf权重 weighttfidf.toarray() #打印每类文本的tf-idf词语权重第一个for遍历所有文本第二个for便利某一类文本下的词语权重 for i in range(len(weight)): print u-------这里输出第,i,u类文本的词语tf-idf权重------ for j in range(len(word)): print word[j],weight[i][j]
运行结果 三. 其他错误解决方法
这里虽然讲解几个安装时遇到的其他错误及解决方法但作者更推荐上面的安装步骤。在这之前我反复的安装、卸载、升级包其中遇到了各种错误改了又改百度了又谷歌。常见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 numpy1.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://www.microsoft.com/en-us/download/details.aspx?id44266 参考文章安装pandas出现错误“error: Microsoft Visual C 10.0 is required (Unable to find vcvarsall.bat).”的解决办法 - OSCHINA - 中文开源技术交流社区 PS这些问题基本解决方法使用pip升级、版本一致、重新下载相关版本exe文件再安装。 总之最后希望文章对你有所帮助尤其是刚学习Python和机器学习的同学。