1.备份原有源
tar -zcvf CentOS-bk.tar.gz /etc/yum.repos.d/CentOS-*
2.替换为阿里云源
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
|
3.nameserver
vim /etc/resolv.conf nameserver 8.8.8.8 nameserver 114.114.114.114
|
并执行
4.安装依赖
yum -y groupinstall "Development tools" yum install -y ncurses-devel gdbm-devel xz-devel sqlite-devel tk-devel uuid-devel readline-devel bzip2-devel libffi-devel yum install -y openssl-devel openssl11 openssl11-devel
|
指定编译版本
export CFLAGS=$(pkg-config --cflags openssl11) export LDFLAGS=$(pkg-config --libs openssl11)
|
5.下载源码包并编译
tar xvzf Python-3.10.4.tgz cd Python-3.10.4
./configure --enable-optimizations && make altinstall
/usr/local/bin/python3.10 --version /usr/local/bin/pip3.10 --version
|
6.建立软连接
ln -sf /usr/local/bin/python3.10 /usr/bin/python3 ln -sf /usr/local/bin/pip3.10 /usr/bin/pip3
|
7.替换源
vim ~/.pip/pip.conf
[global] index-url=https://pypi.tuna.tsinghua.edu.cn/simple/ extra-index-url= http://pypi.douban.com/simple/ http://mirrors.aliyun.com/pypi/simple/ #proxy = [user:passwd@]proxy.server:port [install] trusted-host= # pypi.tuna.tsinghua.edu.cn # pypi.douban.com mirrors.aliyun.com ssl_verify: false
|
pip3 install --upgrade pip
|
9.尝试安装包到指定目录
安装包到指定的目录:
pip install numpy -t /usr/local/lib/python3.10/site-packages
|
参考资料
https://www.zhihu.com/tardis/zm/art/491817098?source_id=1003