본문 바로가기

퍼블릭 클라우드

[aws] amazon Linux 2에 python 3.9를 설치하는 방법

728x90

amazon Linux 2에 python 3.9를 설치하는 방법

테스트 환경

$ cat /etc/os-release
NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"


$ getconf LONG_BIT
64

시스템에 설치된 python version

$ python --version
Python 2.7.18


$ python3 --version
Python 3.7.9

requirements(요구 사항)

yum install -y gcc openssl-devel bzip2-devel libffi-devel
yum install -y wget

python 최신 버전 설치

python 최신 버전 다운로드

https://www.python.org/downloads/source/

cd /usr/local/src
wget https://www.python.org/ftp/python/3.10.6/Python-3.10.6.tgz
tar xf Python-3.10.6.tgz

python 3.10 빌드 및 설치

cd Python-3.10.6
./configure --enable-optimizations
$ ./configure --enable-optimizations
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for python3.10... no
checking for python3... python3
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
...
configure: creating ./config.status
config.status: creating Makefile.pre
config.status: creating Misc/python.pc
config.status: creating Misc/python-embed.pc
config.status: creating Misc/python-config.sh
config.status: creating Modules/ld_so_aix
config.status: creating pyconfig.h
creating Modules/Setup.local
creating Makefile
make altinstall
$ make altinstall
gcc -pthread -c -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall    -fno-semantic-interposition -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fvisibility=hidden  -I./Include/internal  -I. -I./Include    -DPy_BUILD_CORE -o Programs/python.o ./Programs/python.c
...
Looking in links: /tmp/tmpvh0w7rdz
Processing /tmp/tmpvh0w7rdz/setuptools-63.2.0-py3-none-any.whl
Processing /tmp/tmpvh0w7rdz/pip-22.2.1-py3-none-any.whl
Installing collected packages: setuptools, pip
Successfully installed pip-22.2.1 setuptools-63.2.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

python 버전 확인

python3.10 --version
pip3.10 --version
$ python3.10 --version
Python 3.10.6


$ pip3.10 --version
pip 22.2.1 from /usr/local/lib/python3.10/site-packages/pip (python 3.10)

pip 업그레이드

python3.10 -m pip install --upgrade pip

update-alternatives 명령으로 python path 설정

update-alternatives --config python
$ which python3.10
/usr/local/bin/python3.10
update-alternatives --install /usr/bin/python python /usr/local/bin/python3.10 1
update-alternatives --config python
$ update-alternatives --config python

There is 1 program that provides 'python'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/local/bin/python3.10

Enter to keep the current selection[+], or type selection number: 1

python 버전 확인

$ python --version
Python 3.10.6

pip path 설정

$ ls -l /usr/local/bin/pip3.10
-rwxr-xr-x 1 root root 230 Aug 16 21:50 /usr/local/bin/pip3.10
ln -s /usr/local/bin/pip3.10 /usr/bin/pip
pip --version
$ pip --version
pip 22.2.1 from /usr/local/lib/python3.10/site-packages/pip (python 3.10)

 


update-alternatives 명령

$ update-alternatives --help
alternatives version 1.7.4 - Copyright (C) 2001 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.

usage: alternatives --install <link> <name> <path> <priority>
                    [--initscript <service>]
                    [--family <family>]
                    [--slave <link> <name> <path>]*
       alternatives --remove <name> <path>
       alternatives --auto <name>
       alternatives --config <name>
       alternatives --display <name>
       alternatives --set <name> <path>
       alternatives --list

common options: --verbose --test --help --usage --version --keep-missing
                --altdir <directory> --admindir <directory>

set

update-alternatives --set python /usr/bin/python3.8

install

update-alternatives --install /usr/bin/python python /usr/bin/python2.7 2

remove

alternatives --remove python  /usr/local/bin/python3.10
728x90