python3的算法库安装
Python 算法库(记住要以顺序安装)
1. Numpy https://sourceforge.net/projects/numpy/files/NumPy/
2. Scipy https://sourceforge.net/projects/scipy/files/scipy/0.16.1/
3. Matplotlib https://sourceforge.net/projects/matplotlib/files/matplotlib/matplotlib-1.5.1/
4. Scikit-Learn https://sourceforge.net/projects/scikit-learn/files/scikit-learn-0.17.tar.gz/download
安装pip前需要前置安装setuptools
wget –no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
python3.5 setup.py build
python3.5 setup.py install
安装pip(如果你不需要可以不安装)
wget –no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb
tar -zxvf pip-8.0.2.tar.gz
cd pip-8.0.2
python3.5 setup.py build
python3.5 setup.py install
安装scipy库报错raise NotFoundError('no lapack/blas resources found') numpy.distutils.system_info.NotFound
yum install lapack lapack-devel blas blas-devel
python3.5 setup.py install
安装matplotlib报错返回信息:* The following required packages can not be built:
* freetype, png
安装freetype https://sourceforge.net/projects/freetype/files/freetype2/2.4.0/
解压freetype,进入freetype目录,顺序执行如下命令
./configure
make
sudo make install
freetype安装成功
安装 libpng https://sourceforge.net/projects/libpng/files/libpng16/1.6.28/libpng-1.6.28.tar.gz/download
./configure
make
sudo make install
依赖zlib安装zlib https://sourceforge.net/projects/libpng/files/zlib/1.2.10/zlib-1.2.10.tar.gz/download
./configure
make
sudo make install
import matplotlib.pyplot时,报错如下
ImportError: libpng16.so.16: cannot open shared object file
解决方案
http://blog.csdn.NET/zybasjj/article/details/7577313
在/etc/ld.so.conf文件中加入一行
/usr/local/lib
执行如下命令
#sudo ldconfig
搞定
用easy_install时出现unknown url type: https问题,地址不通
Downloading https://pypi.python.org/packages/38/bb/bf325351dd8ab6eb3c3b7c07c3978f38b2103e2ab48d59726916907cd6fb/pyparsing-2.1.10.tar.gz#md5=065908b92904e0d3634eb156f44cc80
解决办法:
1.yum install openssl-devel
2.重新编译安装Python
3.easy_install virtualenv
安装完毕后写个测试程序:mytest1.py
# -*- coding: utf-8 -*-
# Filename : mytest1.py
import numpy as np # 导入numpy库
from numpy import * # 导入numpy库
import matplotlib.pyplot as plt # 导入matplotlib库
# 测试数据集-二维list
dataSet = [[-0.017612,14.053064],[-1.395634 ,4.662541],[-0.752157 ,6.538620],[-1.322371 ,7.152853],[0.423363 ,11.054677],[0.406704 ,7.067335],[0.667394 ,12.741452], [-2.460150 ,6.866805],[0.569411 ,9.548755],[-0.026632 ,10.427743],[0.850433 ,6.920334],[1.347183 ,13.175500],[1.176813 ,3.167020],[-1.781871 ,9.097953]]
dataMat = mat(dataSet).T # 将数据集转换为numpy矩阵,并转置
plt.scatter(dataMat[0],dataMat[1],c='red',marker='o') # 绘制数据集散点图
# 绘制直线图形
X = np.linspace(-2,2,100) # 产生直线数据集
# 建立线性方程
Y = 2.8*X+9
plt.plot(X,Y) # 绘制直线图
plt.show() # 显示绘制后的结果
有图说明主要模块安装成功
效果图:
以上是源码安装,还有可以用whl文件安装 先安装wheel
pip install wheel
whl 文件安装
先进入如下连接下载python和系统版本对应的scipy包:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy
比如我的版本是64位的python 3.42,那么我就下载:
scipy-0.18.1-cp34-cp34m-win_amd64.whl
2
这里有个坑
下载后修改文件名(这就是安装中的坑了,不改是安不了的):
把原来文件名scipy-0.18.1-cp34-cp34m-win_amd64.whl中间的cp34m变为none,这样文件名改为:scipy-0.18.1-cp34-none-win_amd64.whl
如果不改的话不然会出现:
scipy-0.18.1-cp34-cp34m-win_amd64.whl is not a supported wheel on this platform.
3
打开cmd(window键+R,输入cmd就出现),在命令行输入:
pip3 install 路径名/scipy-0.18.1-cp34-none-win_amd64.whl
这样就好了。