python3、pip 源码安装
源码安装 python3
-
下载python包:(华为镜像源):https://mirrors.huaweicloud.com/python/
-
解压:tar -xzvf Python-3.7.16.tgz
-
更新系统包
-
包管理用具为 apt-get
apt-get update
apt-get install -y gcc make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev
-
包管理工具为:yum
yum install zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel
-
-
cd Python-3.7.16
-
生成 Makefile:
./configure --prefix=/usr/local/python3 --enable-shared
-
编译:
make && make install
-
测试:
./python -V
-
错误:
-
3.12 版本在执行 python 时,报错 “./python: error while loading shared libraries: libpython3.12.so.1.0: cannot open shared object file: No such file or directory”
原因:生成 makefile 时
./configure --prefix=/usr/local/python3 --enable-shared
开启了–enable-shared 导致的。解决方法:将源码包里的该文件复制到usr/lib64/里
cp libpython3.12.so libpython3.12.so.1.0 /usr/lib64/
-
安装 pip
- 下载:
curl -O https://bootstrap.pypa.io/get-pip.py
- 安装:
./python3 get-pip.py