Linux/RedHat, CentOS, ubuntu

[ CentOS ] python3로 변경 후 YUM 실행시 SyntaxError: invalid syntax 원인과 해결 방법

Pydole 2019. 12. 20. 19:01

 

python3로 업그레이드 한 후 YUM을 실행했을 때, 에러가 발생하였다.

 

 

 

원인

 

/usr/bin/yum의 파일을 열어보니,

 

import yum을 하였을시 예외처리가 되어 있었다. python3에는 모듈이 없나보다.

 

 

#!/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)

 

pip로 설치를 해봤지만 모듈자체가 없는가 보다...

 


#pip install yum

 

Collecting yum
  Could not find a version that satisfies the requirement yum (from versions: )
No matching distribution found for yum

 

 

 

# pip install yummain


  Could not find a version that satisfies the requirement yummain (from versions: )
No matching distribution found for yummain

 


 

 

해결

 

/usr/bin/yum과 /usr/libexec/urlgrabber-ext-down의 인터프리터를 각각 2버전으로 정정

 

#!/usr/bin/python2