python3编译安装配置(Python 3 compilation and installation configuration)

安装编译依赖&工具

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 libffi-devel -y

下载软件包&解压软件包

wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz
tar -zxvf Python-3.8.1.tgz

配置安装环境

cd Python-3.8.1.tgz
./configure --prefix=/usr/local/python3

编译安装

make && make install

页面提示:Successfully installed pip-21.2.4 setuptools-58.1.0 安装成功

页面提示:Successfully installed pip-21.2.4 setuptools-58.1.0 安装成功

配置环境变量并生效

vim  /etc/profile

点击键盘“o”键在文档最后新增如下代码

#python3.8  configuration
PATH=$PATH:/usr/local/python3/bin:
export PATH

保存并退出vim

点击键盘ESC,输入:wq回车

点击键盘ESC,输入:wq回车

使配置生效

source /etc/profile

验证python3安装是否生效

python3 -V

查看本机自带python2是否可用

python -V

自带python已生效

自带python已生效

注:如果不想用自带的2.7.5 可以进行升级。只需在/etc/profile文件中 新增python2*的路径即可

PATH=$PATH:/usr/local/python3/bin:/usr/local/python2.7.15/bin
————————

Install compile dependency & Tool

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 libffi-devel -y

Download package & unzip package

wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz
tar -zxvf Python-3.8.1.tgz

Configure the installation environment

cd Python-3.8.1.tgz
./configure --prefix=/usr/local/python3

Compile and install

make && make install

页面提示:Successfully installed pip-21.2.4 setuptools-58.1.0 安装成功

页面提示:Successfully installed pip-21.2.4 setuptools-58.1.0 安装成功

Configure environment variables and take effect

vim  /etc/profile

Click “O” on the keyboard to add the following code at the end of the document

#python3.8  configuration
PATH=$PATH:/usr/local/python3/bin:
export PATH

< strong > save and exit VIM < / strong >

Click ESC on the keyboard and enter: WQ enter

Click ESC on the keyboard and enter: WQ enter

< strong > make configuration effective < / strong >

source /etc/profile

Verify that the python 3 installation is in effect

python3 -V

Check whether the native python2 is available

python -V

Native Python has taken effect

Native Python has taken effect

< strong > note: if you don’t want to use the built-in 2.7.5, you can upgrade it. Just add the path of python2 * in the / etc / profile file < / strong >

PATH=$PATH:/usr/local/python3/bin:/usr/local/python2.7.15/bin