package download
sudo dnf install --downloadonly --downloaddir=. python3.11 python3.11-devel python3.11-pip
[appuser@appdev python-rpms]$ sudo yum install -y *.rpm
Failed to set locale, defaulting to C.UTF-8
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered with an entitlement server. You can use subscription-manager to register.
Package chkconfig-1.19.2-1.el8.x86_64 is already installed.
Package mpdecimal-2.5.1-3.el8.x86_64 is already installed.
Dependencies resolved.
=========================================================================================================================
Package Architecture Version Repository Size
=========================================================================================================================
Installing:
python3.11 x86_64 3.11.13-2.el8_10 @commandline 31 k
python3.11-devel x86_64 3.11.13-2.el8_10 @commandline 249 k
python3.11-libs x86_64 3.11.13-2.el8_10 @commandline 10 M
python3.11-pip noarch 22.3.1-5.el8 @commandline 3.2 M
python3.11-pip-wheel noarch 22.3.1-5.el8 @commandline 1.4 M
python3.11-setuptools noarch 65.5.1-4.el8_10 @commandline 2.0 M
python3.11-setuptools-wheel noarch 65.5.1-4.el8_10 @commandline 722 k
Transaction Summary
=========================================================================================================================
Install 7 Packages
Total size: 18 M
Installed size: 71 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : python3.11-setuptools-wheel-65.5.1-4.el8_10.noarch 1/7
Installing : python3.11-pip-wheel-22.3.1-5.el8.noarch 2/7
Installing : python3.11-libs-3.11.13-2.el8_10.x86_64 3/7
Installing : python3.11-3.11.13-2.el8_10.x86_64 4/7
Running scriptlet: python3.11-3.11.13-2.el8_10.x86_64 4/7
Installing : python3.11-setuptools-65.5.1-4.el8_10.noarch 5/7
Installing : python3.11-pip-22.3.1-5.el8.noarch 6/7
Running scriptlet: python3.11-pip-22.3.1-5.el8.noarch 6/7
Installing : python3.11-devel-3.11.13-2.el8_10.x86_64 7/7
Running scriptlet: python3.11-devel-3.11.13-2.el8_10.x86_64 7/7
Verifying : python3.11-3.11.13-2.el8_10.x86_64 1/7
Verifying : python3.11-devel-3.11.13-2.el8_10.x86_64 2/7
Verifying : python3.11-libs-3.11.13-2.el8_10.x86_64 3/7
Verifying : python3.11-pip-22.3.1-5.el8.noarch 4/7
Verifying : python3.11-pip-wheel-22.3.1-5.el8.noarch 5/7
Verifying : python3.11-setuptools-65.5.1-4.el8_10.noarch 6/7
Verifying : python3.11-setuptools-wheel-65.5.1-4.el8_10.noarch 7/7
Installed products updated.
Installed:
python3.11-3.11.13-2.el8_10.x86_64 python3.11-devel-3.11.13-2.el8_10.x86_64
python3.11-libs-3.11.13-2.el8_10.x86_64 python3.11-pip-22.3.1-5.el8.noarch
python3.11-pip-wheel-22.3.1-5.el8.noarch python3.11-setuptools-65.5.1-4.el8_10.noarch
python3.11-setuptools-wheel-65.5.1-4.el8_10.noarch
Complete!
RHEL 8에서 Python 버전을 변경하려면 alternatives --set python /usr/bin/python3 명령을 사용하여 기본 python 명령어를 Python 3로 지정하거나, yum module install 명령으로 원하는 버전(예: Python36, Python38)의 Python을 설치한 후 python3 또는 해당 버전의 명령어로 사용합니다. 시스템의 플랫폼 Python은 RHEL 시스템 도구 전용이므로 직접 수정하지 않아야 합니다.
1. 원하는 Python 버전 설치하기
RHEL 8은 여러 버전의 Python 3을 지원하며, yum module install을 통해 원하는 버전을 병렬로 설치할 수 있습니다.
예를 들어, Python 3.6을 설치하려면 다음 명령어를 사용합니다:
sudo yum module install Python36
Python 2를 설치하려면 Python27 또는 Python2 모듈을 설치할 수 있습니다.
2. 버전 없는 Python 명령어 설정하기
RHEL 8에서는 기본적으로 python 명령어는 설치되지 않거나, python3와 같이 버전이 지정된 명령어를 사용해야 합니다.
python 명령어를 특정 Python 3 버전으로 설정하려면 alternatives 명령어를 사용합니다:
sudo alternatives --set python /usr/bin/python3.6
(위 명령어에서 /usr/bin/python3.6은 설치된 Python 3의 경로로 변경해야 합니다)
설정 후 python --version 명령어로 변경된 버전을 확인할 수 있습니다.
3. 안전한 사용을 위한 권장 방법
가상 환경(Virtual Environment) 사용:
시스템 Python 환경에 영향을 주지 않고 독립적으로 패키지를 설치하고 관리하기 위해 가상 환경을 생성하여 사용하는 것이 가장 안전하고 권장되는 방법입니다.
플랫폼 Python 건드리지 않기:
RHEL 8 시스템 도구에서 사용하는 Platform Python은 직접 수정하거나 사용해서는 안 됩니다. 이는 시스템 전체에 문제를 일으킬 수 있습니다.
명시적으로 버전 지정:
스크립트를 작성할 때는 python3 또는 python3.6과 같이 버전을 명시하여 실행하는 것이 좋습니다.