centos7安装python3.10
时间:2022-10-12 来源:未知 投稿:admin 点击:次
安装依赖:
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 epel-release
yum install -y openssl-devel openssl11 openssl11-devel
下载
本文直接在Centos上下载
mkdir -p /doc/temp && cd /doc/temp
wget http://down1.fwqzx.com/tar.gz/Python-3.10.4.tgz
编译
编译主要需要注意的问题是设置编译FLAG,以便使用最新的openssl库。
export CFLAGS=$(pkg-config --cflags openssl11)
export LDFLAGS=$(pkg-config --libs openssl11)
设置好了之后,进入源码目录
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
配置
配置快捷命令
通过设置软链接简化命令输入
#设置
ln -sf /usr/local/bin/python3.10 /usr/bin/python3
ln -sf /usr/local/bin/pip3.10 /usr/bin/pip3
再验证一下设置是否正确
[root@localhost Python-3.10.3]python3 --version
Python 3.10.3
[root@localhost Python-3.10.3]pip3 --version
pip 22.0.4 from /usr/local/lib/python3.10/site-packages/pip (python 3.10)
配置pip源
由于网络原因,官方的pip源无法访问,会出现类似如下错误
Could not fetch URL https://pypi.org/simple/pip/: There was a problem
confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443):
Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLCertVerificationError(1,
'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer
certificate (_ssl.c:997)'))) - skipping
所以需要替换成国内源,方法如下。
新建pip配置文件
mkdir -p ~/.pip
touch ~/.pip/pip.conf
编辑配置文件,配置如下。
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
上面配置了清华,豆瓣,阿里的源,并且关闭了ssl验证。当然如果有需要还可以设置代理,把注释掉的proxy那行放开即可。
再验证一下
pip3 install --upgrade pip
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 epel-release
yum install -y openssl-devel openssl11 openssl11-devel
下载
本文直接在Centos上下载
mkdir -p /doc/temp && cd /doc/temp
wget http://down1.fwqzx.com/tar.gz/Python-3.10.4.tgz
编译
编译主要需要注意的问题是设置编译FLAG,以便使用最新的openssl库。
export CFLAGS=$(pkg-config --cflags openssl11)
export LDFLAGS=$(pkg-config --libs openssl11)
设置好了之后,进入源码目录
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
配置
配置快捷命令
通过设置软链接简化命令输入
#设置
ln -sf /usr/local/bin/python3.10 /usr/bin/python3
ln -sf /usr/local/bin/pip3.10 /usr/bin/pip3
再验证一下设置是否正确
[root@localhost Python-3.10.3]python3 --version
Python 3.10.3
[root@localhost Python-3.10.3]pip3 --version
pip 22.0.4 from /usr/local/lib/python3.10/site-packages/pip (python 3.10)
配置pip源
由于网络原因,官方的pip源无法访问,会出现类似如下错误
Could not fetch URL https://pypi.org/simple/pip/: There was a problem
confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443):
Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLCertVerificationError(1,
'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer
certificate (_ssl.c:997)'))) - skipping
所以需要替换成国内源,方法如下。
新建pip配置文件
mkdir -p ~/.pip
touch ~/.pip/pip.conf
编辑配置文件,配置如下。
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
上面配置了清华,豆瓣,阿里的源,并且关闭了ssl验证。当然如果有需要还可以设置代理,把注释掉的proxy那行放开即可。
再验证一下
pip3 install --upgrade pip
如果您的问题仍未解决,还可以加入服务器在线技术交流QQ群:8017413寻求帮助。
相关内容