安装python3.9

到网址找下载链接https://www.python.org/downloads/release/python-390/

安装依赖

sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

解压

tar -xf Python-3.X.X.tar.xz

设置并安装

which openssl //用命令查看openssl位置,设置的时候要用,不然安装好以后缺少openssl不能通过https下载包
./configure --enable-optimizations --with-openssl=/usr/local/opt/openssl

nproc //查看进程数
make -j 4 //此处的数字是进程数

sudo make altinstall (sudo make install)
//make install 会直接覆盖系统的python

安装lxml遇到问题

cc -I/usr/include/libxml2 -I/usr/include/libxml2 -c /tmp/xmlXPathInitcfhhalla.c -o tmp/xmlXPathInitcfhhalla.o
    cc tmp/xmlXPathInitcfhhalla.o -lxml2 -o a.out
    error: command '/usr/bin/gcc' failed with exit code 4

有可能是内存不够,我的机器512MB不够,增加虚拟内存到2G以后安装成功