1
0

Ubuntuに複数バージョンのPythonをインストールする

Last updated at Posted at 2022-09-01

自分用の構築手順メモです。

基本は環境を切り替えるのですが、切り替えずに手元でPython3.7、Python3.8、Python3.9あたりを使いたい用件があったので作りました。

引用元文献

こちらの記事を使わせて頂きました。
Ubuntu22.04LTSにPythonPipをインストールする方法
Install packages for Python 3.9 on Ubuntu 22.04
Ubuntuでpythonのバージョンを切り換える

PythonPPAのインポート

sudo add-apt-repository ppa:deadsnakes/ppa -y
sudo apt-get update

Python3のインストール

必要なバージョンのPythonをインストールします。

#sudo apt install python3.7 -y
sudo apt install python3.9 -y
sudo apt install python3.10 -y
sudo apt install python3.11 -y

python3-distutilsのインストール pip3インストール

各バージョンのPythonでpipを使うにはバージョンごとのpython3-distutilsが必要になります。これがないとModuleNotFoundErrorが出ます。

ModuleNotFoundError: No module named 'distutils.util'

2023.12.25追記

以前の手順では各バージョンのpipをインストールできなくなってました。こちら(Python3.8 から 3.10にあげたらpipコマンド使えなくなったんだが)を参考にさせて頂きました。

以下でpip3をインストールします。

#sudo apt install python3.7-distutils
#sudo apt install python3.9-distutils
#sudo apt install python3.10-distutils
#sudo apt install python3.11-distutils
##以下に変更
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.9
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11

update-alternatives

PythonとしてDefault versionを登録したい場合はこちらの記事を参考にupdate-alternativesを使いました。

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