Centos下安装Python3.6
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos下安装Python3.6相关的知识,希望对你有一定的参考价值。
一、安装python3.6.1
1、安装依赖环境
#yum install readline-devel ##必须安装否则会出现python3编译器中不能使用退格键和方向键
2、下载安装包并解压
[[email protected] ~]# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz ##下载安装包
[[email protected] ~]# tar zvxf Python-3.6.1.tgz ##解压安装包
3、 编译并安装
[[email protected] ~]# cd Python-3.6.1 ##进入安装包
[[email protected] Python-3.6.1]# mkdir /usr/local/python3 ##创建安装目录
[[email protected] Python-3.6.1]# ./configure --prefix=/usr/local/python3 ##编译
[[email protected] Python-3.6.1]# make && make install ##安装
4、创建软连接
[[email protected] Python-3.6.1]# mv /usr/bin/python /usr/bin/python_bak ##备份原软连接
[[email protected] Python-3.6.1]# ln -s /usr/local/python3/bin/python3 /usr/bin/python ##chua创建新的软链接使程序运行时不显示版本号
5、测试软件能否正常运行
[[email protected] Python-3.6.1]# python
Python 3.6.1 (default, Apr 21 2018, 16:42:07)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux
Type "help", "copyright", "credits" or "license" for more information.
6、将/usr/local/python3/bin加入到环境变量
[[email protected] Python-3.6.1]# vim ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
[[email protected] Python-3.6.1]# source ~/.bash_profile ##使环境变量生效
[[email protected] Python-3.6.1]# python3 -V ##测试python3正常
Python 3.6.1
[[email protected] Python-3.6.1]# pip3 -V ##测试pip3正常
pip 9.0.1 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)
7、修改yum指向python 旧版本
[[email protected] pip-8.0.2]# vi /usr/bin/yum
#!/usr/bin/python2.6
二、安装pip及setuptools
1、安装pip前需要前置安装setuptools
[[email protected] ~]# wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
[[email protected] ~]# tar zxvf setuptools-19.6.tar.gz
[[email protected] ~]# cd setuptools-19.6
[[email protected] ~]# python3 setup.py build
[[email protected] ~]# python3 setup.py install
2、安装pip
[[email protected] ~]# wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb
[[email protected] ~]# tar zvxf pip-8.0.2.tar.gz
[[email protected] ~]# cd pip-8.0.2
[[email protected] pip-8.0.2]# python3 setup.py build
[[email protected] pip-8.0.2]# python3 setup.py install
以上是关于Centos下安装Python3.6的主要内容,如果未能解决你的问题,请参考以下文章