下载centos7 with python3 docker镜像无法使用yum源的原因以及solution

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Lockey23/article/details/81876674

下载centos7 with python3 docker镜像无法使用yum源的原因以及solution

可能大多数人都不知道yum的可执行程序使用什么语言写的,请看:

[lockey@7-o-1 ~]# cat /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)

很显然,从解释器我们就可以看出使用python写的,看了code部分更是确信无疑,那么错误出在了哪里呢?

分析上边的代码是python2写的,但是镜像的默认python版本是python3,原因很清楚,解释器调用错误,我们只需要将解释器指向正确的位置即可
# whereis python
python: /usr/bin/python /usr/bin/python3.6m /usr/bin/python3.6 /usr/bin/python3.6m-config /usr/bin/python3.6-config /usr/bin/python3.6m-x86_64-config /usr/bin/python2.7 /usr/lib/python3.6 /usr/lib/python2.7 /usr/lib64/python3.6 /usr/lib64/python2.7 /etc/python /usr/include/python3.6m /usr/include/python2.7

将上边解释器改成:

#!/usr/bin/python2.7

这一步过了之后,运行可能还会报错因为要运行的python程序不止这一个地方,所以对于出错的地方要逐个修改解释器路径

猜你喜欢

转载自blog.csdn.net/Lockey23/article/details/81876674
今日推荐