LoginSignup
2
2

More than 1 year has passed since last update.

ubuntu18.04 LTSに「Python3.11」をインストール

Last updated at Posted at 2022-11-12

はじめに

Python 3.11の安定板が2022年10月25日(日本時間)にリリースされました。
https://docs.python.org/3/whatsnew/3.11.html
早速、Ubuntuにインストールしてみます。
僕の環境は、Windows11/WSL2のUbuntu 18.04 LTSです。
以下の作業はWindowsターミナルでUbuntuのbashを選択してやってます。

PPAリポジトリ追加

Python3.11は公式リポジトリにはありません。
まだの場合は、取得可能なPPAリポジトリ(ppa:deadsnakes/ppa)を追加します。

sudo add-apt-repository ppa:deadsnakes/ppa

実行時の画面イメージです。
image.png

リポジトリ追加後はupdate必須

必ず必要です。

sudo apt update

実行時画面イメージです。
image.png

Python3.11の存在確認

python3.11がインストール可能かリポジトリを確認します。

apt search python3.11

このようにでてくればOKです。
image.png

Python3.11のインストール

以下のコマンドでインストールします。

sudo apt install python3.11 -y

念のため、Python3.11のインストールフォルダを確認しておきます。

 which python3.11

結果は「/usr/bin/python3.11」でした。
問題ないです。

実行は「python3.11」で行います

試しにバージョンの確認をしてみます。

python3.11 --version

結果
image.png
OKですね。

Python3のシンボリックリンクは変更NG

たまに「Python3」でも実行できるよう「update-alternatives」をつかって、Python3のカレントを新しいバージョン(今回なら3.11)にする記事をみます。
でも、やめたほうがいいです。
たしかに、

sudo update-alternatives --config python3

を実行して、
image.png
みたいに切り替えること自体は可能です。
でも、それをやってしまうと、かなりの確率で「apt update」がエラーになります。
以下のようなメッセージを見て、うんざりしたくない人はやめたほうがいいです。

ModuleNotFoundError: No module named 'apt_pkg'

ではでは。

2
2
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
2
2