Python3安装
CentOS 6+系统默认安装的python版本是2.6.6,python2版本与python3还有有一些语法上的不一样。我们要把python升级到3版本,但是系统自带的旧版本python被系统很多其他软件环境依赖,所以不能直接卸载原来的2版本,所以我们重新安装一个3版本,将2版本的依赖保留。

1、下载Python安装包

2、安装源码编译器等工具:

[root@bigdata-pro03 softwares]# yum -y install gcc gcc-c++ autoconf automake make zlib zlib-devel

3、解压下好的源码包:

[root@bigdata-pro03 softwares]# tar -xzvf Python-3.6.0.tgz [root@bigdata-pro03 softwares]# cd /opt/modules/Python-3.6.0/ [root@bigdata-pro03 Python-3.6.0]# ls aclocal.m4 configure Grammar Lib Makefile.pre.in Objects PCbuild Python Tools config.guess configure.ac Include LICENSE Misc Parser Programs README config.sub Doc install-sh Mac Modules PC pyconfig.h.in setup.py

4、编译安装包,指定安装路径:

注意:prefix参数用于指定将Python安装在新目录,这样不会覆盖原有的python。
./configure --prefix=/usr/local/python36 make&& make install

5、修改系统默认的Python路径,因为默认的python指向2.6

mv /usr/bin/python /usr/bin/python-2.6.6

6、建立新的软连接,指向Python-3.6.0:

注:这里的python36是第4步指定的安装路径,python3.6是Python包里的可执行程序
ln -s /usr/local/python36/bin/python3.6 /usr/bin/python

7、因为yum是依赖python的,所以这里我们修改了默认的python,就要要修改yum,让其运行指向旧的版本:

vim /usr/bin/yum 将第一行“#!/usr/bin/python” 修改为“#!/usr/bin/python-2.6.6”

8、测试按是否安装成功

[root@bigdata-pro02 Python-3.6.0]# python Python3.6.0 (default, Nov162019,09:39:23) [GCC4.4.720120313 (Red Hat4.4.7-23)] on linux Type"help","copyright","credits" or"license"for more information. >>>
可以看到,已经成功安装Python3.6.0!
pip3安装

1、下载安装文件,使用python命令进行安装

wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py pythonget-pip.py

2、为pip建立软连接,使用pip命令安装requests模块

ln -s /usr/local/python36/bin/pip3.6 /usr/bin/pip pip-V pip install requests
[root@bigdata-pro03 gcc-build-9.2.0]# pip Usage: pip[options] Commands: install Install packages. download Download packages. uninstall Uninstall packages. freeze Output installed packagesin requirements format. list List installed packages. show Show information about installed packages. check Verify installed packages have compatible dependencies. config Manage local andglobal configuration. search Search PyPIfor packages. wheel Build wheelsfrom your requirements. hash Compute hashes of package archives. completion A helper command usedfor command completion. debug Show information usefulfor debugging. help Show helpfor commands. General Options:-h, --help Show help.--isolated Run pipin an isolated mode, ignoring environment variables and user configuration.-v, --verbose Give more output. Optionis additive, and can be used up to3 times.-V, --version Show version and exit.-q, --quiet Give less output. Optionis additive, and can be used up to3 times (corresponding to WARNING, ERROR, and CRITICAL logging levels).--logPath to a verbose appending log.--proxySpecify a proxyin the form [user:passwd@]proxy.server:port.--retriesMaximum number of retries each connection should attempt (default5 times).--timeoutSet the socket timeout (default15 seconds).--exists-actionDefault action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.--trusted-host
Markthis host or host:port pairas trusted, even though it does not have valid or any HTTPS.--certPath to alternate CA bundle.--client-certPath to SSL client certificate, a single file containing theprivate key and the certificatein PEM format.--cache-dirStore the cache datain.--no-cache-dir Disable the cache.--disable-pip-version-check Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index.--no-color Suppress colored output
到此,Centos系统下的Python3环境就搭建完成了!