您的位置:首页 > 编程语言 > Python开发

ubuntukylin-14.04.2-desktop-amd64中python2.7版本安装机器学习库

2017-07-18 00:00 239 查看
本文永久地址:https://my.oschina.net/bysu/blog/1456737

1.如果需要设置代理才能上网,那么先设置代理。

摘自:http://www.cnblogs.com/foonsun/p/5781767.html

ubuntu 全局代理,特别适合虚拟机nat,公司代理上网,强烈推荐

建立/etc/apt/apt.conf文件
其中写入代理,格式如下:

Acquire::http::proxy "http://192.168.2.200:808/";
Acquire::ftp::proxy "ftp://192.168.2.200:808/";
Acquire::https::proxy "https://192.168.2.200:808/";

-----------------------------------------------------------

参考自:http://www.linuxidc.com/Linux/2014-04/100476.htm

2.更换源

可以通过图形界面去更换。

在终端修改和替换源的方法

打开终端,输入命令:

sudo gedit /etc/apt/sources.list

更换完源之后,然后更新:

sudo apt-get update

3.安装numpy+scipy+matlotlib+scikit-learn

由于包之间有依赖关系,建议从上往下的顺序安装

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


Numpy测试代码

from numpy import *
print random.rand(4,4)

SciPy测试代码

import numpy as np
from scipy.stats import beta
from matplotlib.pyplot import hist, plot, show

obs = beta.rvs(5, 5, size=2000)  # 2000 observations
hist(obs, bins=40, normed=True)
grid = np.linspace(0.01, 0.99, 100)
plot(grid, beta.pdf(grid, 5, 5), 'k-', linewidth=2)
show()


MatPlotLib测试代码

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm

fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y, Z = axes3d.get_test_data(0.05)
ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
cset = ax.contour(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm)
cset = ax.contour(X, Y, Z, zdir='x', offset=-40, cmap=cm.coolwarm)
cset = ax.contour(X, Y, Z, zdir='y', offset=40, cmap=cm.coolwarm)

ax.set_xlabel('X')
ax.set_xlim(-40, 40)
ax.set_ylabel('Y')
ax.set_ylim(-40, 40)
ax.set_zlabel('Z')
ax.set_zlim(-100, 100)

plt.show()


----------------------更新时间:2017年8月10日 23:22:28-------------------------------

今天想安装Python的pandas包,于是执行:

sudo apt-get install python-pandas

提示如下错误:

E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

执行如下命令:

sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock

继续安装pandas

sudo apt-get install python-pandas

还是报错,如下:
E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem.

解决方案,执行如下命令:

sudo dpkg --configure -a

执行上面的命令之后继续执行

sudo apt-get update

之后再继续运行安装python-pandas的命令,

参考:
http://blog.csdn.net/xiao_lxl/article/details/53159635 http://www.cnblogs.com/ajianbeyourself/p/4214398.html http://blog.csdn.net/sunbibei/article/details/51191452 http://blog.csdn.net/tterminator/article/details/66478221 http://blog.csdn.net/kevin_android_123456/article/details/8174343 http://blog.csdn.net/gudujianjsk/article/details/7893156
linux中python的IDE:https://download.jetbrains.8686c.com/python/pycharm-community-2017.1.5.tar.gz
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: