본문 바로가기

리눅스

CentOS 7에 Python 3와 pip3를 설치하기

반응형

CentOS 7에 Python 3와 pip3를 설치하기

  • EPEL 저장소 추가
yum install -y epel-release
  • Python 3 설치
    • CentOS 7의 기본 저장소에서 Python 3 패키지를 설치합니다.
sudo yum install -y python3
  • pip3 설치
    • pip3는 Python 3용 패키지 관리자입니다. CentOS 7에서는 python3-pip 패키지를 설치하여 pip3를 사용할 수 있습니다.
sudo yum install -y python3-pip
  • pip3 버전 확인
pip3 --version
$ pip3 --version
pip 21.3.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
  • Python 버전 확인
python --version
$ python --version
Python 2.7.5
  • update-alternatives 명령으로 기본 Python 선택
sudo update-alternatives --config python
$ sudo update-alternatives --config python

3 개의 프로그램이 'python'를 제공합니다.

  선택    명령
-----------------------------------------------
   1           /opt/rh/rh-python38/root/usr/bin/python3
 + 2           /usr/bin/python2.7
*  3           /usr/bin/python3.6

현재 선택[+]을 유지하려면 엔터키를 누르고, 아니면 선택 번호를 입력하십시오:1
  • Python 버전 확인
$ python --version
Python 3.8.11
728x90

ansible 패키지 설치

python -m pip install ansible

ansible 2.9.27 - 리눅스 패키지 매니저(YUM)로 설치된 버전

ansible --version
$ ansible --version
ansible 2.9.27
  config file = /home/tuser/.ansible.cfg
  configured module search path = [u'/home/tuser/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /bin/ansible
  python version = 2.7.5 (default, Jun 28 2022, 15:30:04) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]

ansible [core 2.13.5] - pip 패키지 매니저로 설치된 버전

/opt/rh/rh-python38/root/usr/local/bin/ansible --version
$ /opt/rh/rh-python38/root/usr/local/bin/ansible --version
ansible [core 2.13.5]
  config file = /home/tuser/.ansible.cfg
  configured module search path = ['/home/tuser/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/rh/rh-python38/root/usr/local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/tuser/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/rh/rh-python38/root/usr/local/bin/ansible
  python version = 3.8.11 (default, Sep  1 2021, 12:33:46) [GCC 9.3.1 20200408 (Red Hat 9.3.1-2)]
  jinja version = 3.1.2
  libyaml = True

리눅스 패키지 매니저로 설치된 ansible(ansible-2.9.27) 삭제

rpm -qa | grep ansible
$ rpm -qa | grep ansible
ansible-python3-2.9.27-1.el7.noarch
ansible-2.9.27-1.el7.noarch

 

yum remove -y ansible-2.9.27 ansible-python3-2.9.27

** 패키지 삭제 시 에러가 발생하며 python을 2.7 버전으로 변경 후 삭제를 진행합니다.

sudo update-alternatives --config python

 

ansible --version
$ ansible --version
-bash: ansible: command not found

환경변수 등록(ansible [core 2.13.5] PATH 등록)

vim ~/.bash_profile
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/opt/rh/rh-python38/root/usr/local/bin

 

cat ~/.bash_profile | grep rh-python38
$ cat ~/.bash_profile | grep rh-python38
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/opt/rh/rh-python38/root/usr/local/bin

 

ansible --version
$ ansible --version
ansible [core 2.13.5]
  config file = /home/tuser/.ansible.cfg
  configured module search path = ['/home/tuser/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/rh/rh-python38/root/usr/local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/tuser/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/rh/rh-python38/root/usr/local/bin/ansible
  python version = 3.8.11 (default, Sep  1 2021, 12:33:46) [GCC 9.3.1 20200408 (Red Hat 9.3.1-2)]
  jinja version = 3.1.2
  libyaml = True

 

728x90
반응형