search
LoginSignup
25
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

posted at

updated at

EC2(Amazon Linux 2)にPython 3.8, Pip 3.8をインストールする

Amazon Linux2 に Python 3.8をインストール

Python 3.8, Pip 3.8をAmazon Linux2にインストールでお困りの方は参考にしてください。

  • EC2 AMI
     Amazon Linux 2 AMI (HVM)
     SSD Volume Type
     ami-062f7200baf2fa504 (64 ビット x86)/ami-0e98ccceff552e8a8 (64 ビット Arm)

事前準備

$ sudo yum -y update
$ sudo yum -y install gcc openssl-devel bzip2-devel libffi-devel

ダウンロード

$ wget https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgz
$ tar xzf Python-3.8.1.tgz

インストール

$ cd Python-3.8.1
$ sudo ./configure --enable-optimizations
$ sudo make altinstall

確認

$ python3.8 --version
Python 3.8.1
$ pip3.8 --version
pip 19.2.3 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)

rootのpathを設定

rootからもPython3.8を使えるようにパスを通しシンボリックリンクをはっておく

$ sudo which python3.8
which: no python3.8 in (/sbin:/bin:/usr/sbin:/usr/bin)
$ sudo visudo
(Before)
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin
(After)
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
$ sudo which python3.8
/usr/local/bin/python3.8
$ sudo ln -s /usr/local/bin/python3.8 /usr/local/bin/python3
$ sudo which python3
/usr/local/bin/python3
$ sudo ln -s /usr/local/bin/pip3.8 /usr/local/bin/pip3
$ sudo which pip3
/usr/local/bin/pip3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
25
Help us understand the problem. What are the problem?