Python3安装配置:
为了了防止安装Python3之后出现以下错误:
ModuleNotFoundError: No module named '_sqlite3'
我们需要先安装sqlite-devel:
# yum -y install sqlite-devel
因为我们要编译安装 Python3,所以要提前安装编译工具及库文件
# yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-
devel
下载Python3
https://www.python.org/downloads/
# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
安装python3
我个人习惯安装在/usr/local/python3(具体安装位置看个人喜好)
创建目录:
# mkdir -p /usr/local/python3
解压下载好的Python-3.x.x.tgz包(具体包名因你下载的Python具体版本不不同而不不同,如:我
下载的是Python3.6.1.那我这⾥里里就是Python-3.6.1.tgz)
# tar -zxvf Python-3.6.1.tgz
进入解压后的目录,编译安装。
# cd Python-3.6.1
# ./configure --prefix=/usr/local/python3
make
# make
make install
# make install
建立python3的软链
# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
并将/usr/local/python3/bin加⼊入PATH
# 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回⻋车退出。
修改完记得执行行下面的命令,让上一步的修改生效:
# source ~/.bash_profile
检查Python3及pip3是否正常可⽤用:
# python3 -V
Python 3.6.1
# pip3 -V
pip 9.0.1 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)