centos8 python3.9をインストールして実行する

centos7でpython3.9をインストールするまでの手順を記述してます。CentOSのバージョンはStream release 8となります。
環境
- OS CentOS Stream release 8
- python 3.9.2
事前準備
必要なツールをインストールしておきます。
アップデートしておきます。
1 |
sudo dnf -y update |
ツールをインストールします。
1 2 |
sudo dnf groupinstall "Development Tools" -y sudo dnf install openssl-devel libffi-devel bzip2-devel -y |
Python 3.9ダウンロード
こちらのサイトで最新バージョンを確認してダウンロードします。

現時点では3.9.2が最新だったので、3.9.2をダウンロードします。
1 |
sudo wget https://www.python.org/ftp/python/3.9.2/Python-3.9.2.tgz |
※wgetがなければインストールしておきます。
1 |
sudo dnf install wget -y |
python3.9インストール
ダウンロードが完了したのでインストールを開始します。
まずはダウンロードしたファイルを解凍します。
1 |
tar xvf Python-3.9.2.tgz |
解凍したディレクトリに移動します。
1 |
cd Python-3.9*/ |
設定を行います。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
./configure --enable-optimizations checking for GCC >= 4.7 __atomic builtins... yes checking for ensurepip... upgrade checking if the dirent structure of a d_type field... yes checking for the Linux getrandom() syscall... yes checking for the getrandom() function... yes checking for library containing shm_open... -lrt checking for sys/mman.h... (cached) yes checking for shm_open... yes checking for shm_unlink... yes checking for pkg-config... /usr/bin/pkg-config checking whether compiling and linking against OpenSSL works... yes checking for X509_VERIFY_PARAM_set1_host in libssl... yes checking for --with-ssl-default-suites... python checking for --with-builtin-hashlib-hashes... md5,sha1,sha256,sha512,sha3,blake2 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 |
ビルドを行います。
1 |
sudo make altinstall |
バージョンを確認します。
1 2 3 4 |
python3.9 --version <出力結果> Python 3.9.2 |
パッケージ管理ツールであるpipのバージョンも確認します。
1 2 3 4 |
pip3.9 --version <出力結果> pip 20.2.3 from /usr/local/lib/python3.9/site-packages/pip (python 3.9) |
Hello Worldしてみる
「hello.py」という名前で、以下のコードを記述します。
1 2 3 4 |
vi hello.py <編集> print("Hello World") |
実行します。
1 2 3 4 |
python3.9 hello.py <出力結果> Hello World |
-
前の記事
SQL Server バージョンを確認する 2021.02.20
-
次の記事
Composerのバージョンを1系に変更する 2021.02.20
コメントを書く