蜗牛kuai快跑

导航

python安装scipy、sklearn以及matplotlib

依赖关系:scipy的安装需要依赖于numpy、lapack、atlas,而numpy和sci的测试程序的运行又依赖于nose。

                    sklearn依赖于numpyscipy函数库。

根据依赖关系安装numpy后,安装scipy

1.在命令行输入:pip install scipy

2.错误处理

 (1)错误:no lapack/blas resources found 

 解决方法,安装lapack:sudo apt-get install liblapack-dev

 (2)错误:error: library dfftpack has Fortran sources but no Fortran compiler found 

 解决方法,安装Fortran compiler:sudo apt-get install gfortran

 

 结果又出现问题******warning"using deprecated Numpy API,disable it by"******

 这时就有点不解了,因为numpy的版本是1.12,已经很新了。

 

后来在终于找到一线曙光:

 一开始直接使用pip 安装 numpy 结果失败了,后来查了一些资料,总结了一下。

 1.安装python-dev

 安装这个包,以后安装各种python扩展包,可以省很多事情。

 sudo apt-get install python-dev

 2.使用apt-get 安装

 sudo apt-get install python-numpy
sudo apt-get install python-scipy
sudo apt-get install python-matplotlib

 3.使用pip 安装

 之前使用pip 安装失败, 查过原因之后,是因为缺少了编译所需的库,可以先用apt-get 来安装所需库。

 sudo apt-get build-dep python-numpy
 sudo apt-get build-dep python-scipy

 之后在使用 pip 应该可以(未测试)

sudo pip install numpy
sudo pip install scipy

继续安装sklearn
使用pip安装:sudo pip install sklearn
安装过程中虽然会出现多次warning,但是可以安装成功

最后安装matplotlib
使用pip安装:sudo pip install matplotlib

至此,则全部包安装完成了!!!

***执行.py文件时,出现错误***

错误1._tkinter.TclError: no display name and no $DISPLAY environment variable

在文件中添加:import matplotlib

       matplotlib.use('Agg')

 

测试代码:

# -*- coding: utf-8 -*-
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

from matplotlib.pyplot import savefig

x = np.linspace(0, 10, 1000)
y = np.sin(x)
z = np.cos(x**2)

plt.figure(figsize=(8,4))
plt.plot(x,y,label="$sin(x)$",color="red",linewidth=2)
plt.plot(x,z,"b--",label="$cos(x^2)$")
plt.xlabel("Time(s)")
plt.ylabel("Volt")
plt.title("PyPlot First Example")
plt.ylim(-1.2,1.2)
plt.legend()
savefig('matFig.jpg')
plt.show()

 

posted on 2017-03-14 11:52  蜗牛kuai快跑  阅读(707)  评论(0)    收藏  举报