Linux-安装python3环境
[root@node1 ~]# yum -y groupinstall "Development tools"
[root@node1 ~]# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
[root@node1 ~]# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
[root@node1 ~]# mkdir -p /usr/local/python3
[root@node1 ~]# tar -zxf Python-3.6.1.tgz
查看是否下载成功
[root@node1 ~]# cd Python-3.6.1
[root@node1 Python-3.6.1]# ls
aclocal.m4 configure Grammar Lib Makefile.pre.in Objects PCbuild Python Tools
config.guess configure.ac Include LICENSE Misc Parser Programs README.rst
config.sub Doc install-sh Mac Modules PC pyconfig.h.in setup.py
安装和设定
[root@node1 Python-3.6.1]# ./configure --prefix=/usr/local/python3
[root@node1 Python-3.6.1]# make && make install
[root@node1 Python-3.6.1]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
编辑环境变量
[root@node1 Python-3.6.1]# vim ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH
声明环境变量
升级pip
[root@node1 Python-3.6.1]# source ~/.bash_profile
[root@node2 Python-3.6.1]# pip3 install --upgrade pip
Collecting pip
Downloading https://files.pythonhosted.org/packages/5c/e0/be401c003291b56efc55aeba6a80ab790d3d4cece2778288d65323009420/pip-19.1.1-py2.py3-none-any.whl (1.4MB)
100% |████████████████████████████████| 1.4MB 155kB/s
Installing collected packages: pip
Found existing installation: pip 9.0.1
Uninstalling pip-9.0.1:
Successfully uninstalled pip-9.0.1
Successfully installed pip-19.1.1
查看版本
[root@one ~]# python3 -V
Python 3.6.1
[root@one ~]# pip3 -V
pip 19.1.1 from /usr/local/python3/lib/python3.6/site-packages/pip (python 3.6) # 如果没有出现这一条,下面的命令就不要执行了
[root@one ~]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
安装完成!!!