1. 安装依赖环境
# 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
2下载文件
https://www.python.org/downloads/
# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
3.安装python3
我个人习惯安装在/usr/local/python3(具体安装位置看个人喜好)
创建目录:
1 | # mkdir -p /usr/local/python3 |
解压下载 的包 # tar -zxvf Python-3.6.1.tgz
4.进入解压后的目录,编译安装。
1 2 | # cd Python-3.6.1 # ./configure --prefix=/usr/local/python3 |
make install 或者 make && make install |
5.建立python3的软链
1 | # ln -s /usr/local/python3/bin/python3 /usr/bin/python3 |
6.并将/usr/local/python3/bin加入PATH
1 2 3 4 5 6 7 8 9 | # 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 |
按ESC,输入:wq回车退出。
修改完记得执行行下面的命令,让上一步的修改生效:
1 | # source ~/.bash_profile |
检查Python3及pip3是否正常可用:
1 2 3 4 | # python3 -V Python 3.6 . 1 # pip3 -V pip 9.0 . 1 from / usr / local / python3 / lib / python3. 6 / site - packages (python 3.6 ) |
二、安装pip以及setuptools
毕竟丰富的第三方库是python的优势所在,为了更加方便的安装第三方库,使用pip命令,我们需要进行相应的安装。
1、安装pip前需要前置安装setuptools
命令如下:
wget –no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
tar -zxvf setuptools-19.6.tar.gz
cd setuptools-19.6
python3 setup.py build
python3 setup.py install
2、安装pip
命令如下:
wget –no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-9.0.3.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb
tar -zxvf pip-9.0.3.tar.gz
cd pip-9.0.3
python3 setup.py build
python3 setup.py install
错误:
configure: error: no acceptable C compiler found in $PATH
需要安装gcc套件:yum install gcc
wget不是命令:yum -y install wget