CentOS 7 originally shipped with Python 2 for system tools. Python 3 can be installed alongside it, but replacing the system Python can break
yum and other components.CentOS 7 and its bundled Python versions are end-of-life. Migrate to a supported operating system and Python version for production. The following notes are for maintaining a legacy system.
Check installed versions
bash_snippet
Bash · 4 lines|
| command -v python |
| python --version |
| command -v python3 |
| python3 --version |
Install Python 3 alongside the system interpreter
On an appropriately configured CentOS 7 system with the relevant packages available, a distribution package can be installed with:
bash_snippet
Bash · 3 lines|
| sudo yum install python3 |
| python3 --version |
| python3 -m pip --version |
Package availability and versions depend on configured repositories. CentOS 7 repositories may be archived, and the version supplied may itself be unsupported. For a supported Python runtime, migrate the host or use an appropriately maintained isolated environment compatible with your infrastructure.
Building from source
If a legacy environment requires a source build, verify the release archive and build dependencies, install into a separate prefix, and test required modules such as
ssl. The Python release must support the host's compiler and libraries. Use version-specific commands and an isolated virtual environment.Do not replace
/usr/bin/python, modify yum's shebang, or overwrite the operating system's Python. Those steps can damage system management tools.✦ 卷终 · 柯航存卷 ✦