본문 바로가기
  • 배움에는 끝이 없다.
Operating System/linux

[linux] CentOS7 "yum No module named yum" 오류

by 줘패자 2023. 8. 31.

⊙ 관련 이슈 https://access.redhat.com/discussions/3300621
기본적으로 yum은 python 2.7 버전을 사용하고 있었음 
python을 3.6으로 업데이트하면서 문법적 문제가 발생하는 상황이 많다.

 

After updating python yum stop working - Red Hat Customer Portal

Access Red Hat’s knowledge, guidance, and support through your subscription.

access.redhat.com

 

[증상 및 에러 확인]

[root@test ~]# yum clean all
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named yum
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:
2.7.9 (default, Dec 21 2020, 13:12:23)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq

 

[해결방법]
1번 yum / python 관련 라이브러리 재설치 
2번 python3 실행 관련 명령어를 심볼릭 링크로 생성하여 처리

 

1) yum / python 관련 라이브러리 재설치  방법

[확인]
[root@test ~]# rpm -qa
yum-utils-1.1.31-54.el7_8.noarch
yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch
yum-metadata-parser-1.1.4-10.el7.x86_64
yum-3.4.3-168.el7.centos.noarch
 
[root@test ~]# rpm -qa |grep python-2
audit-libs-python-2.8.4-4.el7.x86_64
libxml2-python-2.9.1-6.el7_2.3.x86_64
python-2.7.5-80.el7_6.x86_64
libselinux-python-2.5-14.1.el7.x86_64
libsemanage-python-2.5-14.el7.x86_64
policycoreutils-python-2.5-29.el7_6.1.x86_64
[root@q391-1252 ~]# rpm -qa |grep python-libs
python-libs-2.7.5-80.el7_6.x86_64
[root@q391-1252 ~]# rpm -qa |grep url
python-pycurl-7.19.0-19.el7.x86_64
libcurl-devel-7.29.0-51.el7.x86_64
curl-7.29.0-51.el7.x86_64
python-urlgrabber-3.10-9.el7.noarch
libcurl-7.29.0-51.el7.x86_64
 
[root@test ~]# ll /usr/bin/python*
lrwxrwxrwx. 1 root root 7 2019-07-03 00:35 /usr/bin/python -> python2
lrwxrwxrwx. 1 root root 9 2019-07-03 00:35 /usr/bin/python2 -> python2.7
-rwxr-xr-x. 1 root root 7216 2019-06-21 05:28 /usr/bin/python2.7
lrwxrwxrwx 1 root root 9 2019-07-11 16:04 /usr/bin/python3 -> python3.6
lrwxrwxrwx 1 root root 18 2019-07-11 16:04 /usr/bin/python36 -> /usr/bin/python3.6
-rwxr-xr-x 2 root root 11408 2019-04-26 06:05 /usr/bin/python3.6
-rwxr-xr-x 2 root root 11408 2019-04-26 06:05 /usr/bin/python3.6m

[설치]
python2 버전 사용도중 python3 버전으로 업데이트 한경우 간혹 python2 패키지가 삭제되어 오류가 발생하는 경우가 있습니다
ㄴ위에 해당 패키지 없는경우 관련 패키지를 다시 다운로드해준후에 설치하면 정상적으로 작동합니다.

[root@test ~]# wget http://repo.telcobridges.com/centos/7/os/x86_64/Packages/python-2.7.5-80.el7_6.x86_64.rpm
[root@test ~]# wget http://repo.telcobridges.com/centos/7/os/x86_64/Packages/python-libs-2.7.5-80.el7_6.x86_64.rpm
[root@test ~]# wget https://buildlogs.centos.org/c7.2003.00.ppc64le/python-urlgrabber/20200401093002/3.10-10.el7.ppc64le/python-urlgrabber-3.10-10.el7.noarch.rpm

yum 관련 패키지 다운로드
[root@test ~]# wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm
[root@test ~]# wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
[root@test ~]# wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
[root@test ~]# wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm

 

 

2)  python3 실행관련 명령어를 심볼릭 링크로 생성하여 오류 처리

[root@test ~]# unlink /bin/python
[root@test ~]# ln -s /bin/ptyhon3.6 /bin/python3
[root@test ~]# ln -s /bin/ptyhon3.6 /bin/python

yum 명령어 실행하여 정상 작동확인
[root@test ~]# yum clean all

yum 실행시 정상작동하지 않으면 아래와 같이 수정하여 조치

[root@test ~]# vi /usr/bin/yum
에디터 실행후 첫 줄

#!/usr/bin/python => #!/usr/bin/python2 변경후 저장

python 3.x버전의 pip가 정상작동하도록 심볼릭 링크 설정

[root@test ~]# ln -s /bin/pip3.6 /bin/pip3

php3 버전 확인 및 python 버전 확인

 

댓글