centos6安装Python3环境

Python3安装

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

1、下载Python安装包

源码包下载地址:https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz

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

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

centos6安装Python3环境

3、解压下好的源码包:

[root@bigdata-pro03 softwares]# tar -xzvf Python-3.6..tgz
[root@bigdata-pro03 softwares]# cd /opt/modules/Python-3.6./
[root@bigdata-pro03 Python-3.6.]# 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

centos6安装Python3环境

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

注意:prefix参数用于指定将Python安装在新目录,这样不会覆盖原有的python。

./configure --prefix=/usr/local/python36
make && make install

centos6安装Python3环境

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

mv /usr/bin/python /usr/bin/python-2.6.  

centos6安装Python3环境

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

注:这里的python36是第4步指定的安装路径,python3.6是Python包里的可执行程序

ln -s /usr/local/python36/bin/python3. /usr/bin/python

centos6安装Python3环境

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

vim /usr/bin/yum

将第一行“#!/usr/bin/python”

修改为“#!/usr/bin/python-2.6.”

centos6安装Python3环境

8、测试按是否安装成功

[root@bigdata-pro02 Python-3.6.]# python
Python 3.6. (default, Nov , ::)
[GCC 4.4. (Red Hat 4.4.-)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

centos6安装Python3环境

可以看到,已经成功安装Python3.6.0!

pip3安装

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

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

centos6安装Python3环境

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

ln -s /usr/local/python36/bin/pip3. /usr/bin/pip
pip -V
pip install requests

centos6安装Python3环境

[root@bigdata-pro03 gcc-build-9.2.]# pip

Usage:
pip <command> [options] Commands:
install Install packages.
download Download packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
check Verify installed packages have compatible dependencies.
config Manage local and global configuration.
search Search PyPI for packages.
wheel Build wheels from your requirements.
hash Compute hashes of package archives.
completion A helper command used for command completion.
debug Show information useful for debugging.
help Show help for commands. General Options:
-h, --help Show help.
--isolated Run pip in an isolated mode, ignoring environment variables and user configuration.
-v, --verbose Give more output. Option is additive, and can be used up to times.
-V, --version Show version and exit.
-q, --quiet Give less output. Option is additive, and can be used up to times (corresponding to WARNING, ERROR,
and CRITICAL logging levels).
--log <path> Path to a verbose appending log.
--proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port.
--retries <retries> Maximum number of retries each connection should attempt (default times).
--timeout <sec> Set the socket timeout (default seconds).
--exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
--trusted-host <hostname> Mark this host or host:port pair as trusted, even though it does not have valid or any HTTPS.
--cert <path> Path to alternate CA bundle.
--client-cert <path> Path to SSL client certificate, a single file containing the private key and the certificate in PEM
format.
--cache-dir <dir> Store the cache data in <dir>.
--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

centos6安装Python3环境

到此,Centos系统下的Python3环境就搭建完成了!

上一篇:201521123082 《Java程序设计》第1周学习总结


下一篇:Linux下安装python3环境搭建