一、下载源码
https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
二、编译参数
--prefix:指定安装目录
使用–prefix参数可以指定Python的安装目录,例如:
./configure --prefix=/usr/local/python38
这将把Python 3.8安装在/usr/local/python38目录下。
–enable-optimizations:启用优化
使用–enable-optimizations参数可以启用优化,例如:
./configure --prefix=/usr/local/python38 --enable-optimizations
这将在编译Python时启用优化选项,提高Python的运行效率。
–enable-shared:启用共享库
使用–enable-shared参数可以启用共享库,例如:
./configure --prefix=/usr/local/python38 --enable-optimizations --enable-shared
这将在编译Python时生成共享库,方便其他程序共享Python的库文件。
–with-openssl:指定OpenSSL库
如果需要使用SSL加密功能,可以使用–with-openssl参数指定OpenSSL库的路径,例如:
./configure --prefix=/usr/local/python38 --enable-optimizations --enable-shared --with-openssl=/usr/local/openssl
这将在编译Python时链接指定的OpenSSL库,以支持SSL加密功能。
三、编译
- 配置
./configure --prefix=/usr/local/python38 --enable-optimizations \
--enable-shared --with-openssl=/usr/local/openssl
- 安装
make && sudo make install
四、修改 pip 源
更改pip源,不论pip还是pip3都是再用户目录下创建pip.conf文件:
mkdir ~/.pip
vim ~/.pip/pip.conf
pip.conf写入:
[global]
timeout = 6000
index-url = http://mirrors.aliyun.com/pypi/simple/
trusted-host = pypi.tuna.tsinghua.edu.cn
参考:
https://blog.sacus.top/archives/1223 (编译参数)