Python3源码编译安装

0x00 本文适用范围

Kali/Ubuntu等属于Debian系,依赖库选择Debian分支。

CentOS有专用依赖库版本。

0x01 源码下载与依赖安装

https://www.python.org/downloads/

按需要的版本选择,博主本次安装python3.7.9,选择Gzipped source tarball即可。

# 解压源码
tar -zxvf Python-3.7.9.tgz

# Debian依赖库安装
sudo apt install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip m4 -y
sudo apt-get install --reinstall zlibc zlib1g zlib1g-dev -y
sudo apt install libssl-dev libncurses5-dev libsqlite3-dev libreadline-dev libtk8.5 libgdm-dev libdb4o-cil-dev libpcap-dev libffi-dev libncursesw5-dev libgdbm-dev tk-dev openssl -y

# CentOS依赖库安装
yum -y groupinstall "Development tools"
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
yum install -y libffi-devel zlib1g-dev
yum install zlib* -y

0x03 编译安装

# 生成编译文件清单,prefix指定安装路径,默认是/usr/local
# sudo ./configure --prefix=/usr/local/python3.7.9 --with-openssl=/usr/local/openssl --enable-shared  # 适用于自编译openssl的情况

# 直接使用系统库的ssl更便捷
sudo ./configure --prefix=/usr/local/python3.7.9 --with-ssl --enable-shared 

# 编译安装
make install

# 建立快捷方式
ln -s /usr/local/python3.7.9/bin/python3.7 /usr/bin/python3

# 设置动态链接库路径
echo "/usr/local/python3.7.9/lib/" >> /etc/ld.so.conf

# 刷新动态链接库路径缓存
ldconfig

# 验证命令
python3 --version

# 切换源为国内
python3 -m pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/

 

posted @ 2020-09-19 17:43  DXCyber409  阅读(77)  评论(0编辑  收藏  举报