系统自带的是2.7,再装个3.5的真的感受好麻烦,折腾啊html
1. 源码下载python
https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tar.xz
下载下来后长传到服务器上面
解压:
tar -xvf Python-3.5.0.tar.xz
2.安装配套的库及程序linux
由于缺乏gcc,无法make,因此安装gcc服务器
yum -y install gcc
若是按照python3的话还会提示没ssl,因此先按装sslpython2.7
yum install openssl-devel
新建一个文件夹socket
mkdir /usr/local/python3
备份原来的pythonspa
mv /usr/bin/python /usr/bin/python_old2
如今若是安装python的话,会发现pip没给装,通常都是在python里面的,因此仍是先装下其余的。.net
安装setuptools,通常是缺乏zlib,会报debug
因此先安装zlib3d
yum install zlib yum install zlib-devel
下载setuptools
https://pypi.python.org/pypi/setuptools/38.2.5
上传到服务器后解压
unzip setuptools-38.2.5.zip
进入文件夹后安装
cd setuptools-38.2.5 python setup.py install
接下来能够安装python3了
cd Python-3.5.0 ./configure --prefix=/usr/local/python3 make make install
如今输入python -V还不会出现3.5,建个软链接
ln -s /usr/local/python3/bin/python3 /usr/bin/python
而后pip也建一个软链接
ln -s /usr/local/python3/bin/pip3.5 /usr/local/bin/pip
接下来顺便升级下pip
pip install --upgrade pip
须要安装什么库用pip install libname就行
装完以后会发现yum不能用,原来啊yum的功能用了python脚本,可是咱们已经把原来的python给移除了,因此要修改下yum对应的脚本。这也是为啥咱们不能把python2.7给卸载掉的缘由
vi /usr/bin/yum
把!/usr/bin/python改为!/usr/bin/python_old2
同理把/etc/yum/pluginconf.d/fastestmirror.conf和/etc/yum.conf也改下。
若是还报
Loaded plugins: fastestmirror Determining fastest mirrors
解决方法:
vi /etc/yum/pluginconf.d/fastestmirror.conf
[main]
enabled=0 //把1改成0
verbose=0
socket_timeout=3
hostfilepath=/var/cache/yum/timedhosts.txt
maxhostfileage=10
maxthreads=15
#exclude=.gov, facebook
vi /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1 #将plugins的值修改成0
installonly_limit=5
参考资料:
1.http://blog.sina.com.cn/s/blog_7e513d7e01015j9b.html
2.http://blog.csdn.net/hunyxv/article/details/51597852
3.https://www.cnblogs.com/feng18/p/5854912.html
4.https://www.cnblogs.com/idotest/p/5442173.html
5.https://www.cnblogs.com/zrz43/p/4895635.html
6.http://www.linuxidc.com/Linux/2017-03/142335.htm