编译安装python3

安装依赖

sudo apt-get install zlib1g-dev libbz2-dev libssl-dev libncurses5-dev libsqlite3-dev

 sudo apt-get install zlib1g-dev libbz2-dev libssl-dev libncurses5-dev libsqlite3-dev

  sudo apt-get install -y wget build-essential libreadline-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev

  sudo apt-get install libffi-dev
  sudo apt-get install libssl-dev
  sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev

以上有重复的,本人使用第一行,安装成功。

源代码编译安装软件的步骤:

python+django+虚拟环境(virtualenv[wrapper])+nginx+uwsgi在linux中的安装配置

1.下载软件的源代码

wget https://www.python.org/ftp/python/3.8/Python-3.8.3.tar.xz

3.解压缩软件源代码

xz -d python-3.8.3.tar.xz

tar -xf python-3.8.3.tar

4.切换到root: sudo i,并切换进入源代码目录

cd /opt/python-3.8

5. ./configure释放编译文件,make 编译,make install 编译安装

./configure --prefix=/opt/python38/    #注意提示,可能需要根据提示添加参数  会生成makefile文件

make && make install   # 这两部走完,才会生成创建上面的文件夹

6.检查安装路径是否正确

/opt/python38

查看python38下的bin目录,python3的执行文件都在这里

7.配置软连接,快捷启动配置软连接,快捷启动。或者直接把pthon38/bin写入环境变量(如下,尽量用这一步)5354 ln -s /opt/python38/bin/python3 /usr/bin/python355 ln -s /opt/python38/bin/pip3 /usr/bin/pip356 

8.配置系统环境变量,配置PATH,加入python3的目录

#尽量用这一步

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/opt/python347/bin/
#这一步尽量别用了
PATH=$PATH:/opt/python347/bin/
#配置环境变量需谨慎,如果配错了,你的其他命令也会丢失!
9.写入个人配置文件,永久生效/etc/profile
vim /etc/profile #编辑个人配置文件,写入PATH
PATH=$PATH:/opt/python38/bin/
source /etc/profile #读取一下配置文件,生效配置。

编译安装python3.8.3