CentOs8にPython 3.8をインストールする手順

CentOs8にPython 3.8をインストールする手順

現時点で最新版のpython3.8をCentOs8にインストールする手順を記述してます。 仮想環境の構築までの手順も記述してます。

環境

  • OS CentOS Linux release 8.0.1905 (Core)
  • Python 3.8.2

必要パッケージインストール

インストールに必要なパッケージをインストールします。

sudo dnf groupinstall 'development tools'
sudo dnf install bzip2-devel expat-devel gdbm-devel ncurses-devel openssl-devel readline-devel sqlite-devel tk-devel xz-devel zlib-devel wget

pythonダウンロード

こちらのサイトから最新版を確認してダウンロードします。

VERSION=3.8.2
wget https://www.python.org/ftp/python/${VERSION}/Python-${VERSION}.tgz

解凍して移動します。

tar -xf Python-${VERSION}.tgz
cd Python-${VERSION}

pythonインストール

最適化を行います。

./configure --enable-optimizations

コア数を確認してからビルドします。

## コア数確認
nproc

<出力結果>
4

## ビルド
sudo make -j 4

インストールします。

sudo make altinstall

バージョンを確認します。

python3.8 --version

<出力結果>
Python 3.8.2

仮想環境構築

バージョン違いにより、他のプロジェクトなどに影響しないように、仮想環境を構築します。

mkdir ~/testdir
cd ~/testdir

仮想環境作成

python3.8 -m venv testdir_venv
source testdir_venv/bin/activate
python -v

抜けるときは「ctrl + D」で抜けれます。通常のshellに戻すには、下記のコマンド実行します。

deactivate