LoginSignup
1
0

More than 1 year has passed since last update.

Ubuntu 20.04(WSL2)にPython 3.9.13 をインストールする

Posted at

概要

掲題の通り。

環境

$ uname -a
Linux PC 5.10.16.3-microsoft-standard-WSL2 #1 SMP Fri Apr 2 22:23:49 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/issue
Ubuntu 20.04.4 LTS \n \l

方法

依存関係をインストール

Python のビルドに必要な依存関係をインストールする。

sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev

ソース コードをダウンロード

以下のページで対象のソースコード(のダウンロードリンク)を探してwgetでダウンロードする。

wget https://www.python.org/ftp/python/3.9.13/Python-3.9.13.tgz

展開

ダウンロードが完了したら gzip アーカイブを展開する。

tar -xf Python-3.9.13.tgz

configureを実行

ディレクトリを切り替えて、configureを実行します。

cd Python-3.9.13/
./configure --enable-optimizations

ビルド

Python 3.9 ビルド プロセスを開始する。

make -j 8

nprocを実行すると自環境のプロセッサのコア数を確認できる。

インストール

Python バイナリをインストールする。

sudo make altinstall

完了

バージョンを確認する。

python3.9 --version
Output
Python 3.9.13
1
0
0

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
  3. You can use dark theme
What you can do with signing up
1
0