python安装机器学习库 numpy、scipy、matplotlib、scikit-learn
Posted on 2017-03-02 17:52 来碗酸梅汤 阅读(318) 评论(0) 编辑 收藏 举报准备工作
1、yum -y install bzip2-devel(或源码安装)
2、tar -zxvf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
python setup.py build
python setup.py install
1、安装pip
yum安装pip
yum -y install python-pip
1、卸载pip(前提是yum安装pip失败了,或者没有用 )
yum remove python-pip
2、下载
curl -O https://pypi.python.org/packages/source/p/pip/pip-7.1.2.tar.gz
3、安装
解压后 进入目录 python setup.py build
python setup.py install
4、还遇到一个问题 提示说 /usr/bin 目录找不到pip
找一下安装在哪儿 find / -name "pip"
然后运行一下是否可用
最后建立一个软连接在报错的目录
ln -s /usr/local/bin/pip2.7 /usr/bin/pip
2、安装numpy
pip install numpy(若失败,源码安装)
3、安装scipy
依赖包
yum -y install lapack-devel freetype freetype-devel libpng libpng-devel blas blas-devel lapack atlas
pip install scipy(或源码安装)
4、安装matplotlib
tar -zxvf matplotlib-1.2.0.tar.gz
cd matplotlib-1.2.0
python setup.py build
python setup.py install
测试matplotlib
import numpy as np
import matplotlib.pyplot as plt
xData = np.arange(0,10,1)
yData1 = xData.__pow__(2.0)
yData2 = np.arange(15,61,5)
plt.figure(num=1, figsize=(8,6))
plt.title('Plot 1', size=14)
plt.xlabel('x-axis', size=14)
plt.ylabel('y-axis', size=14)
plt.plot(xData, yData1, color='b', linestyle='--', marker='o', label='y1 data')
plt.plot(xData, yData2, color='r', linestyle='-', label='y2 data')
plt.legend(loc='upper left')
plt.savefig('../plot1.png', format='png')
5、安装sklearn
tar -zxvf scikit-learn-0.17.tar.gz
cd scikit-learn-0.17
python setup.py build
python setup.py install
检测
python
Python 2.7.11 (default, Jan 22 2017, 10:03:27)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy
<module 'numpy' from '/usr/local/python27/lib/python2.7/site-packages/numpy/__init__.pyc'>
>>> import scipy
>>> scipy
<module 'scipy' from '/usr/local/python27/lib/python2.7/site-packages/scipy/__init__.pyc'>
>>> import matplotlib
>>> matplotlib
<module 'matplotlib' from '/usr/local/python27/lib/python2.7/site-packages/matplotlib/__init__.pyc'>
>>> import sklearn
>>> sklearn
<module 'sklearn' from '/usr/local/python27/lib/python2.7/site-packages/sklearn/__init__.pyc'>
>>> exit()