Python3 安装后问题(yum/https)

修复Python3安装后yum命令及HTTPS连接问题
文章讲述了在安装Python3后,yum命令出现SyntaxError报错,原因是yum默认依赖python2.x。解决方案是将yum命令文件的第一行修改为指向python2.7。另外,Python3访问HTTPS连接报错是由于openssl版本不匹配,需要下载并安装合适版本的openssl,然后卸载并重新安装Python3,确保其与openssl正确配置。

Python3 安装后yum命令报错

问题:

“File "/usr/bin/yum", line 30
 
    except KeyboardInterrupt, e:
 
                            ^
 
SyntaxError: invalid syntax”

分析:

原 python命令软连接指向linux默认安装的python2.x版本、
安装python3时将原python命令的软连接指向了python3 、

yum命令正常情况下调用python2.x 版本、所以需要修改yum命令文件

解决方案:

修改yum命令文件

vi  /usr/bin/yum

第一行

#!/usr/bin/python
修改为
#!/usr/bin/python2.7


Python3 访问https连接报错

问题:

Can\'t connect to HTTPS URL because the SSL module is not available

分析:

openssl 版本不合适
yum源中的openssl版本过低
应下载新版本openssl安装
卸载python3重新安装

解决方案:

下载合适的openssl版本
可去官网寻找新版本安装文件https://www.openssl.org/source/
此处选择openssl-1.1.1t版本 与python3.10.9适配

openssl1.1.1t安装包
python3.10.9 安装包

下载openssl

wget https://www.openssl.org/source/openssl-1.1.1t.tar.gz --no-check-certificate 

解压安装openssl

tar -zxf openssl-1.1.1t.tar.gz 
cd openssl-1.1.1t
./Configure --prefix=/usr/local/openssl #设置安装目录 
make -j && make install  #编译并安装

重新安装 python3
注意此时需将python3卸载干净

切换到 python3 解压包目录
已经编译过的可以先 make clean 清理一下

./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl --with-openssl-rpath=auto 
make -j && make install

安装Python3 步骤可以参考此文章

Linux 安装 Python3

python3一定要卸载干净

可以参考命令

whereis python
which python
Traceback (most recent call last): File "/usr/share/PackageKit/helpers/yum/yumBackend.py", line 2666, in get_updates ygl = self.yumbase.doPackageLists(pkgnarrow=&#39;updates&#39;) File "/usr/lib/python2.7/site-packages/yum/__init__.py", line 3018, in doPackageLists for (n,a,e,v,r) in self.up.getUpdatesList(): File "/usr/lib/python2.7/site-packages/yum/__init__.py", line 1094, in <lambda> up = property(fget=lambda self: self._getUpdates(), File "/usr/lib/python2.7/site-packages/yum/__init__.py", line 838, in _getUpdates self._up = rpmUtils.updates.Updates(self.rpmdb.simplePkgList(), self.pkgSack.simplePkgList()) File "/usr/lib/python2.7/site-packages/yum/__init__.py", line 1075, in <lambda> pkgSack = property(fget=lambda self: self._getSacks(), File "/usr/lib/python2.7/site-packages/yum/__init__.py", line 778, in _getSacks self.repos.populateSack(which=repos) File "/usr/lib/python2.7/site-packages/yum/repos.py", line 347, in populateSack self.doSetup() File "/usr/lib/python2.7/site-packages/yum/repos.py", line 122, in doSetup self.ayum.plugins.run(&#39;prereposetup&#39;) File "/usr/lib/python2.7/site-packages/yum/plugins.py", line 188, in run func(conduitcls(self, self.base, conf, **kwargs)) File "/usr/lib/yum-plugins/fastestmirror.py", line 197, in prereposetup_hook if downgrade_ftp and _len_non_ftp(repo.urls) == 1: File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 881, in <lambda> urls = property(fget=lambda self: self._geturls(), File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 878, in _geturls self._baseurlSetup() File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 827, in _baseurlSetup mirrorurls.extend(self._getMirrorList()) File "/usr/lib/python2.7/site-packages/yum/yumRepo.py", line 2006, in _getMirrorList print "Could not retrieve mirrorlist $s error was\n$s: $s" $ (url, e.args[0], misc.to_unicode(e.args[1])) UnicodeEncodeError: &#39;ascii&#39; codec can&#39;t encode characters in position 173-177: ordinal not in range(128)
最新发布
09-09
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

为什么不问问神奇的海螺呢丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值