【Python 3.6.1】CentOS 6.5 安装 Python 3.6.1
Python环境有多种方式,yum安装、rpm包安装、源码安装,本测试采用的是源码安装。
Linux:虚拟机下安装的CentOS 6.5,网卡选用桥接,虚拟机可上网,便于下载介质及软件包
1 2 3 |
[root@yujiu ~]# cat /etc/redhat-release CentOS release 6.5 (Final) [root@yujiu ~]# |
下载Python 3.6.1
1 2 3 4 5 6 7 8 |
[root@yujiu ~]# mkdir /soft [root@yujiu ~]# cd /soft/ [root@yujiu soft]# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz ……下载过程略…… [root@yujiu soft]# ls -l 总用量 22016 -rw-r--r--. 1 root root 22540566 3月 21 15:47 Python-3.6.1.tgz [root@yujiu soft]# |
解tar包至/usr/local目录下
1 2 3 4 5 6 7 8 9 10 |
[root@yujiu soft]# tar -xzvf Python-3.6.1.tgz -C /usr/local/ ……过程略…… [root@yujiu soft]# cd /usr/local/Python-3.6.1/ [root@yujiu Python-3.6.1]# ls aclocal.m4 Doc LICENSE Objects pyconfig.h.in config.guess Grammar Mac Parser Python config.sub Include Makefile.pre.in PC README.rst configure install-sh Misc PCbuild setup.py configure.ac Lib Modules Programs Tools [root@yujiu Python-3.6.1]# |
Linux系统安装必要的开发包,因为CentOS作者采用的是最小化安装,只安装了桌面。在安装Python时需要对其进行编译,所以在CentOS中需要安装开发相关的软件包
1 2 3 |
[root@yujiu Python-3.6.1]# yum -y group install development [root@yujiu Python-3.6.1]# yum -y install zlib-devel [root@yujiu Python-3.6.1]# yum -y install openssl-devel |
编译
1 2 |
[root@yujiu Python-3.6.1]# ./configure [root@yujiu Python-3.6.1]# make && make install |
确认已安装环境
1 2 3 4 5 6 7 8 |
[root@yujiu ~]# which python3 /usr/local/bin/python3 [root@yujiu ~]# [root@yujiu ~]# python3 Python 3.6.1 (default, Jul 3 2017, 01:38:52) [GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> |
Python登录交互命令行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[root@dt ~]# python Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> exit() [root@dt ~]# 我们会发现,直接输入python登录到操作系统默认的python环境,如果想登录到刚刚安装的python3.6.1,那么只能输入python3。 为了方便操作,输入python登录到python3环境,那么只需要在.bash_profile中增加alias即可 [root@dt ~]# vi .bash_profile alias python=python3 [root@dt ~]# . .bash_profile [root@dt ~]# python Python 3.6.1 (default, Jul 2 2017, 16:09:42) [GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> |
退出python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[root@dt ~]# python Python 3.6.1 (default, Jul 2 2017, 16:09:42) [GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> exit() [root@dt ~]# 或者 [root@dt ~]# python Python 3.6.1 (default, Jul 2 2017, 16:09:42) [GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> quit() [root@dt ~]# 或者 输入Ctrl + d |