Python in RHEL 8

To install Python2 or 3


yum install python3
 or
yum install python2

Why not just “Python”

[root@ip-172-31-41-9 init.d]# python
-bash: python: command not found
[root@ip-172-31-41-9 init.d]# 

That’s why you can use the alternatives mechanism to enable the unversioned python command system-wide

alternatives --set python /usr/bin/python3
[root@ip-172-31-41-9 init.d]# alternatives --set python /usr/bin/python3
[root@ip-172-31-41-9 init.d]# python
Python 3.6.8 (default, Aug 18 2020, 08:33:21) 
[GCC 8.3.1 20191121 (Red Hat 8.3.1-5)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Note that this works only for the python command itself. Packages and other commands don’t have configurable unversioned variants. Even if you configure python, the commands yum install python-requests or pip won’t work.

Always use the explicit version in these cases. Better yet, don’t rely on the wrapper scripts for pip, venv and other Python modules that you call from the command line. Instead use python3 -m pip, python3 -m venv, python2 -m virtualenv.

猜你喜欢

转载自blog.csdn.net/m0_37859032/article/details/112235062