由于我们的应用程序适用于python2
RHEL 8,因此我们需要迁移到 RHEL 8
在 RHEL 8 机器上安装后python2
,我们看到以下内容:
rpm -qa | grep python2
python2-pip-9.0.3-19.module+el8.6.0+13001+ad200bd9.noarch
python2-setuptools-wheel-39.0.1-13.module+el8.4.0+9442+27d0e81c.noarch
python2-pip-wheel-9.0.3-19.module+el8.6.0+13001+ad200bd9.noarch
python2-2.7.18-11.module+el8.7.0+15681+7a92afba.x86_64
python2-libs-2.7.18-11.module+el8.7.0+15681+7a92afba.x86_64
python2-setuptools-39.0.1-13.module+el8.4.0+9442+27d0e81c.noarch
但是当我们尝试使用 时import yum
,我们会收到有关“没有名为 yum 的模块”的错误,并显示以下输出:
python
Python 2.7.18 (default, Jun 17 2022, 07:56:00)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-13)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import yum
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named yum
yum 安装的 rpm 为:
rpm -qa | grep yum
yum-4.4.2-11.el8.noarch
yum-utils-4.0.18-4.el8.noarch
yum 显示为:
more /usr/bin/yum
#!/usr/bin/python
import sys
try:
import yum
except ImportError:
print >> sys.stderr, """\
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
%s
Please install a package which provides this module, or
verify that the module is installed correctly.
It's possible that the above module doesn't match the
current version of Python, which is:
%s
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
""" % (sys.exc_value, sys.version)
sys.exit(1)
sys.path.insert(0, '/usr/share/yum-cli')
try:
import yummain
yummain.user_main(sys.argv[1:], exit_code=True)
except KeyboardInterrupt, e:
print >> sys.stderr, "\n\nExiting on user cancel."
sys.exit(1)
从pip2
列表中我们得到这个输出:
pip2 list
pip (9.0.3)
setuptools (39.0.1)
那么为什么我们会收到有关 的错误 No module named yum
?
https://www.getpagespeed.com/solutions/python-scripts-running-on-rocky-linux-8-can-not-import-yum
在查看了StackO 问题后,一个简单的修复可能是对
/usr/bin/yum
. 将第一行更改!#/usr/bin/python
为!#/usr/bin/python2.7
2023 年 4 月 25 日起,还有一个更新但更复杂的RHEL 客户门户解决方案。
决议
决议1
决议2
根本原因)