wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz 下载
tar -zxvf Python-3.5.1.tgz 解压
-
cd Python-3.5.1
./configure
make && make install 进入python目录,安装
-
安装过程中出现不能编译的情况 ,提示:no acceptable C compiler found in $PATH
提示没有编译器环境,安装gcc就可以了:yum install gcc -y
-
安装完成,输入python,出现的是python2.7,这是因为RHEL自带python2.7,输入python3就可以了
使用过程中,出现方向键和删除键乱码的情况 ,这是因为默认只安装了readline模块而没有安装readline-devel模块,所以只要安装下即可:yum install readline-devel,安装后再重新安装下python3. 使用正常
yum install python36
转载
(一)简述
刚安装的centos7.4版本默认是安装Python2.7,由于一些命令需要使用的原因,比如yum等,使用的是2.7.5版本的,由于现在很多库包括django都是使用Python3,
因此,有这样的需求:yum使用python2.7版本,django和其他的使用默认的python3版本。
(二)查看并备份python2相关信息
1,使用python -V 可以查看默认的版本信息。
[root@localhost ~]# python -VPython 2.7.5
2,然后使用which python 查看下python的可执行文件的位置。
[root@localhost ~]# which python/usr/bin/python
3,可执行文件在/usr/bin/目录下,查看有关python的文件,ll /usr/bin/python*。通过查看可以得知python默认指向的是python2.7
[root@localhost ~]# ll /usr/bin/python*lrwxrwxrwx. 1 root root 7 Dec 21 15:23 /usr/bin/python -> python2 lrwxrwxrwx. 1 root root 9 Dec 21 15:23 /usr/bin/python2 -> python2.7-rwxr-xr-x. 1 root root 7136 Aug 4 2017 /usr/bin/python2.7
重要:通过查看可以得知python默认指向的是python2.7,由于还没有安装python3,可以先备份python文件,等python3安装好了后再创建软连接即可
4,备份默认python2.7版本
[root@localhost bin]# mv /usr/bin/python /usr/bin/python.bak
(三)方法一:安装配置python3
1,安装相关的包yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
[root@localhost bin]# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc makeLoaded plugins: fastestmirror base | 3.6 kB 00:00:00 extras | 3.4 kB 00:00:00 updates | 3.4 kB 00:00:00 Loading mirror speeds from cached hostfile Package zlib-devel-1.2.7-17.el7.x86_64 already installed and latest version Package 1:openssl-devel-1.0.2k-8.el7.x86_64 already installed and latest version Package ncurses-devel-5.9-14.20130511.el7_4.x86_64 already installed and latest version Package sqlite-devel-3.7.17-8.el7.x86_64 already installed and latest version Package gcc-4.8.5-16.el7_4.1.x86_64 already installed and latest version Package 1:make-3.82-23.el7.x86_64 already installed and latest version Resolving Dependencies --> Running transaction check ---> Package bzip2-devel.x86_64 0:1.0.6-13.el7 will be installed
2,去python官网下载稳定版(https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz)
[root@localhost usr]# wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz--2018-03-08 00:05:54-- https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz Resolving www.python.org (www.python.org)... 151.101.228.223, 2a04:4e42:12::223Connecting to www.python.org (www.python.org)|151.101.228.223|:443... connected. HTTP request sent, awaiting response... 200 OKLength: 16992824 (16M) [application/octet-stream] Saving to: ‘Python-3.6.4.tar.xz’16% [==============> ] 2,781,624 49.4KB/s eta 4m 49s
3,安装python3
[root@localhost tmp]# tar xf Python-3.6.1.tar.xz[root@localhost tmp]# cd Python-3.6.1[root@localhost Python-3.6.1]# ./configure prefix=/usr/local/python3[root@localhost Python-3.6.1]# make &&make install
4,在/usr/bin/下创建软连接
[root@localhost Python-3.6.1]# ln -s /usr/local/python3/bin/python3 /usr/bin/python[root@localhost Python-3.6.1]# python -VPython 3.6.1[root@localhost Python-3.6.1]# python2 -VPython 2.7.5[root@localhost Python-3.6.1]# ll /usr/bin/python*lrwxrwxrwx 1 root root 32 Mar 7 05:38 /usr/bin/python -> /usr/local/python3.6/bin/python3 lrwxrwxrwx. 1 root root 9 Jan 29 16:34 /usr/bin/python2 -> python2.7-rwxr-xr-x. 1 root root 7136 Aug 4 2017 /usr/bin/python2.7lrwxrwxrwx. 1 root root 7 Jan 29 16:34 /usr/bin/python2.bak -> python2
5,配置正常使用yum,使yum使用python2.7版本,否则会报错的。
5.1,修改/usr/bin/yum文件把#! /usr/bin/python修改为#! /usr/bin/python2
[root@localhost Python-3.6.1]# vim /usr/bin/yum #!/usr/bin/python2
5.2,修改/usr/libexec/urlgrabber-ext-down文件,把里面的#! /usr/bin/python 也要修改为#! /usr/bin/python2
[root@localhost Python-3.6.1]# vim /usr/libexec/urlgrabber-ext-down #! /usr/bin/python2
6,如果使用pip的话,简历pip3的软连接。
[root@localhost Python-3.6.1]#ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3[root@localhost Python-3.6.1]# ll /usr/bin/pip3lrwxrwxrwx 1 root root 29 Mar 7 05:41 /usr/bin/pip3 -> /usr/local/python3.6/bin/pip3
至此,一台服务器上默认的版本是python3 ,同时python2页存在了,可以正常使用yum来进行安装所需的软件了。
安装 setuptools
命令:
yum install python-setuptools
完成之后,就可以使用 easy_install 命令安装 django
easy_install django