有人能解释一下python的这种行为吗?

rpppsulh  于 2021-09-08  发布在  Java
关注(0)|答案(0)|浏览(258)

我在docker容器中运行py 2.7.18,在centos 7中使用rh-python27包。
我的一个项目需要 gitdb 包,当我运行docker容器时,它抱怨没有找到gitdb。但我在req.txt中提到了这一点。
我在docker容器中进行故障排除,发现以下行为。有人能给我解释一下这种行为的原因吗。为什么? python 指的是 opt/rh/python27.... 而不是 /usr/bin/python ?

  1. root@cicd-docker CENTOS7 /usr/bin > pwd
  2. /usr/bin
  3. root@cicd-docker CENTOS7 /usr/bin > ./python
  4. Python 2.7.18 (default, Oct 23 2020, 13:34:23)
  5. [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
  6. Type "help", "copyright", "credits" or "license" for more information.
  7. >>> import os
  8. >>> os.__file__
  9. '/usr/lib64/python2.7/os.pyc'
  10. >>> import gitdb
  11. >>> exit()
  12. root@cicd-docker CENTOS7 /usr/bin > python
  13. Python 2.7.18 (default, Oct 23 2020, 13:34:23)
  14. [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
  15. Type "help", "copyright", "credits" or "license" for more information.
  16. >>> import os
  17. >>> os.__file__
  18. '/opt/rh/python27/root/usr/lib64/python2.7/os.pyc'
  19. >>> import gitdb
  20. Traceback (most recent call last):
  21. File "<stdin>", line 1, in <module>
  22. ImportError: No module named gitdb
  23. >>> exit()
  24. root@cicd-docker CENTOS7 /usr/bin > sudo python
  25. Python 2.7.5 (default, Nov 16 2020, 22:23:17)
  26. [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
  27. Type "help", "copyright", "credits" or "license" for more information.
  28. >>> import os
  29. >>> os.__file__
  30. '/usr/lib64/python2.7/os.pyc'
  31. >>> import gitdb
  32. >>> exit()
  33. root@cicd-docker CENTOS7 /usr/bin >

或者,在centos docker中安装python2.7.18的正确方法是什么。
提前谢谢。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题