• 欢迎关注微信公众号:九万里大数据
  • 请使用Ctrl+D收藏本站到书签栏
  • 手机也可访问本站 jwldata.com

centos下安装python3

操作系统 九万里大数据 2年前 (2021-05-18) 529次浏览 0个评论 扫描二维码
文章目录[隐藏]

安装依赖包

一次性解决python3版本中的依赖(No module)问题

yum install bzip2-devel db4-devel gdbm-devel libpcap-devel ncurses-devel openssl-devel readline-devel sqlite-devel tk-devel xz-devel zlib-devel

编译安装

下载安装包并解压

wget https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tgz
tar -zxf Python-3.9.5.tgz
cd Python-3.9.5

配置安装路径

./configure --prefix=/usr/local/Python-3.9.5

centos下安装python3

编译安装

make && make install

centos下安装python3

创建软链接

ln -s /usr/local/Python-3.9.5/bin/python3 /usr/bin/python3
ln -s /usr/local/Python-3.9.5/bin/pip3 /usr/bin/pip3

配置环境变量

vi /etc/profile
 
# python-3.9.5
export PYTHON_HOME=/usr/local/Python-3.9.5
export PATH=$PATH:$PYTHON_HOME/bin
 
source /etc/profile

测试验证

centos下安装python3

相关报错

在安装python3后,使用默认的pip3安装package,假如报“Can’t connect to HTTPS URL because the SSL module is not available.”的错误。网上很多教程是更换成HTTP的国内源,其实归根到底还是python源码包编译安装前没有安装好openssl-devel依赖包,导致在import ssl时报错。需要做的就是重新安装依赖包,然后重新编译安装python3。

[root@centos1 ~]# sudo pip3 install virtualenv virtualenvwrapper
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/
Could not fetch URL https://pypi.org/simple/virtualenv/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/virtualenv/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
ERROR: Could not find a version that satisfies the requirement virtualenv (from versions: none)
ERROR: No matching distribution found for virtualenv
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
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("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

欢迎关注我的微信公众号“九万里大数据”,原创技术文章第一时间推送。
欢迎访问原创技术博客网站 jwldata.com,排版更清晰,阅读更爽快。


centos下安装python3
 


本站文章,如未注明,均为原创 | 原创文章版权归九万里大数据所有,未经许可不得转载。
本文链接:centos下安装python3
喜欢 (0)

您必须 登录 才能发表评论!