1.下载源码
https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
2.解压到得到:/software/tool/Python-3.5.2/
3.环境准备,安装zlib-devel和openssl-devel等
yum -y install gcc-c++ zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
4.创建安装目录
mkdir -p /usr/local/python3.5.2
5.指定配置到安装的目录
/software/tool/Python-3.5.2/configure --prefix=/usr/local/python3.5.2
6.遇到异常(编译时,文件没有拷贝到安装目录):
#gcc: error: Parser/tokenizer_pgen.o: No such file or directory
cp /software/tool/Python-3.5.2/Parser/tokenizer_pgen.o /usr/local/python3.5.2/Parser/tokenizer_pgen.o
#gcc: error:Parser/printgrammar.o: No such file or directory
cp /software/tool/Python-3.5.2/Parser/printgrammar.o /usr/local/python3.5.2/Parser/printgrammar.o
#gcc: error: Parser/parsetok_pgen.o No such file or directory
cp /software/tool/Python-3.5.2/Parser/parsetok_pgen.o /usr/local/python3.5.2/Parser/parsetok_pgen.o
#gcc: error: Parser/pgenmain.o: No such file or directory
cp /software/tool/Python-3.5.2/Parser/pgenmain.o /usr/local/python3.5.2/Parser/pgenmain.o
#make: *** [Parser/pgen] Error 1
cp /software/tool/Python-3.5.2/Parser/pgen /usr/local/python3.5.2/Parser/pgen
#gcc: error: Programs/_testembed.o: No such file or directory
cp /software/tool/Python-3.5.2/Programs/_testembed.o /usr/local/python3.5.2/Programs/_testembed.o
#make: *** [Programs/_testembed] Error 1
cp /software/tool/Python-3.5.2/Programs/_testembed /usr/local/python3.5.2/Programs/_testembed
#(安装了此模块,就不会存在ImportError: No module named 'math'异常)gcc: error: Modules/_math.o: No such file or directory
cp /software/tool/Python-3.5.2/Modules/_math.o /usr/local/python3.5.2/Modules/_math.o
7.编译 make
8.执行安装 make install
9.建立软连接(临时环境变量,或者直接9.1步骤) ln -s /usr/local/python3.5.2/bin/python3 /usr/bin/python3
9.1.持久环境变量
vim /etc/profile
#Python
export PYTHON_HOME=/usr/local/python3.5.2
export PATH=$PATH:$PYTHON_HOME/bin source /etc/profile
10.执行python3
网友评论