現在の問題
$ sudo apt upgrade
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
libpython3.12 : Depends: libpython3.12-stdlib (= 3.12.9-1+focal1) but 3.12.7-1+focal1 is installed
libpython3.12-dev : Depends: libpython3.12-stdlib (= 3.12.9-1+focal1) but 3.12.7-1+focal1 is installed
python3.12-dev : Depends: python3.12 (= 3.12.9-1+focal1) but 3.12.7-1+focal1 is installed
python3.12-venv : Depends: python3.12 (= 3.12.9-1+focal1) but 3.12.7-1+focal1 is installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
apt upgrade
を実施すると、Pythonの依存関係のエラーが発生する。
エラーを読んでみると、どうやらインストールされているPython関連のパッケージと要求バージョンが一致しない模様
- インストール済みバージョン:3.12.7-1+focal1
- 要求されるバージョン:3.12.9-1+focal1
提示された自動修正のコマンドを実行
$ apt --fix-broken install
Preparing to unpack .../python3.12_3.12.9-1+focal1_amd64.deb ...
Unpacking python3.12 (3.12.9-1+focal1) over (3.12.7-1+focal1) ...
dpkg: error processing archive /var/cache/apt/archives/python3.12_3.12.9-1+focal1_amd64.deb (--unpack):
trying to overwrite '/usr/bin/python3.12', which is also in package python3.12-minimal 3.12.7-1+focal1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Preparing to unpack .../libpython3.12-stdlib_3.12.9-1+focal1_amd64.deb ...
Unpacking libpython3.12-stdlib:amd64 (3.12.9-1+focal1) over (3.12.7-1+focal1) ...
dpkg: error processing archive /var/cache/apt/archives/libpython3.12-stdlib_3.12.9-1+focal1_amd64.deb (--unpack):
trying to overwrite '/etc/python3.12/sitecustomize.py', which is also in package libpython3.12-minimal:amd64 3.12.7-1+focal1
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
/var/cache/apt/archives/python3.12_3.12.9-1+focal1_amd64.deb
/var/cache/apt/archives/libpython3.12-stdlib_3.12.9-1+focal1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
依存関係は修正されず、エラーが続く。
上記で、同様のエラーの解決方法を記載されていたので、同じ手順でやってみる。(これでは解決しませんでした)
Python 3.12関連のパッケージ確認
$ dpkg -l |grep python3.12
iU libpython3.12:amd64 3.12.9-1+focal1 amd64 Shared Python runtime library (version 3.12)
iU libpython3.12-dev:amd64 3.12.9-1+focal1 amd64 Header files and a static library for Python (v3.12)
ii libpython3.12-minimal:amd64 3.12.7-1+focal1 amd64 Minimal subset of the Python language (version 3.12)
ii libpython3.12-stdlib:amd64 3.12.7-1+focal1 amd64 Interactive high-level object-oriented language (standard library, version 3.12)
ii postgresql-plpython3-12 12.22-0ubuntu0.20.04.2 amd64 PL/Python 3 procedural language for PostgreSQL 12
ii python3.12 3.12.7-1+focal1 amd64 Interactive high-level object-oriented language (version 3.12)
iU python3.12-dev 3.12.9-1+focal1 amd64 Header files and a static library for Python (v3.12)
ii python3.12-minimal 3.12.7-1+focal1 amd64 Minimal subset of the Python language (version 3.12)
iU python3.12-venv 3.12.9-1+focal1 amd64 Interactive high-level object-oriented language (pyvenv binary, version 3.12)
確かに、バージョン不一致が確認できますね。
パッケージの詳細確認
$ apt show python3.12 python3.12-minimal
~~
APT-Sources: http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal/main amd64 Packages
参考にしたQiitaの記事と同様に、deadsnakeという(ディストリビューション?)のPythonバージョンが入っていた。
依存関係を確認
$ apt rdepends python3.12 python3.12-minimal
python3.12
Reverse Depends:
Depends: libpython3.12-testsuite (>= 3.12.9-1+focal1)
Recommends: python3.12-minimal
Depends: python3.12-venv (= 3.12.9-1+focal1)
Depends: python3.12-tk
Depends: python3.12-gdbm
Depends: python3.12-full (= 3.12.9-1+focal1)
Depends: python3.12-examples (>= 3.12.8-1+focal1)
Depends: python3.12-examples (>= 3.12.9-1+focal1)
Depends: python3.12-dev (= 3.12.9-1+focal1)
Depends: python3.12-dbg (= 3.12.9-1+focal1)
Depends: libpython3.12-testsuite (>= 3.12.8-1+focal1)
Depends: idle-python3.12
Enhances: idle-python3.12
Depends: idle-python3.12
Enhances: idle-python3.12
python3.12-minimal
Reverse Depends:
Depends: python3.12 (= 3.12.7-1+focal1)
$ apt rdepends libpython3.12-minimal libpython3.12-stdlib libpython3.12-minimal
libpython3.12-minimal
Reverse Depends:
Depends: libpython3.12-stdlib (= 3.12.7-1+focal1)
Depends: python3.12-minimal (= 3.12.7-1+focal1)
libpython3.12-stdlib
Reverse Depends:
Depends: python3.12 (= 3.12.7-1+focal1)
Depends: libpython3.12 (= 3.12.9-1+focal1)
Recommends: libpython3.12-minimal
Depends: python3.12 (= 3.12.9-1+focal1)
Depends: libpython3.12-dev (= 3.12.9-1+focal1)
Depends: libpython3.12-dbg (= 3.12.9-1+focal1)
libpython3.12-minimal
Reverse Depends:
Depends: libpython3.12-stdlib (= 3.12.7-1+focal1)
Depends: python3.12-minimal (= 3.12.7-1+focal1)
Pythonの依存関係があるパッケージを削除
参考にした記事の通り、依存関係が発生しているPythonパッケージを削除
$ sudo apt remove python3.12-minimal libpython3.12-minimal
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
libpython3.12 : Depends: libpython3.12-stdlib (= 3.12.9-1+focal1) but 3.12.7-1+focal1 is to be installed
libpython3.12-dev : Depends: libpython3.12-stdlib (= 3.12.9-1+focal1) but 3.12.7-1+focal1 is to be installed
libpython3.12-stdlib : Depends: libpython3.12-minimal (= 3.12.7-1+focal1) but it is not going to be installed
python3.12 : Depends: python3.12-minimal (= 3.12.7-1+focal1) but it is not going to be installed
python3.12-dev : Depends: python3.12 (= 3.12.9-1+focal1) but 3.12.7-1+focal1 is to be installed
python3.12-venv : Depends: python3.12 (= 3.12.9-1+focal1) but 3.12.7-1+focal1 is to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
ここも、依存関係が発生してしまっていて解決できない。
解決方法
最終手段、Pythonパッケージを削除します。
postgresql-plpython3-12
以外を削除対象とします。 これは PostgreSQL の拡張機能であり、Python 3.12 に直接依存しない可能性があるためです。
Ubuntuにデフォルトで入ってるPythonは、システムと依存関係がある場合が大いにあります。
事前に十分にご確認ください。
関連のパッケージ削除
ご自身の依存関係に合わせて削除してください。
$ sudo apt purge libpython3.12:amd64 libpython3.12-dev:amd64 libpython3.12-minimal:amd64 libpython3.12-stdlib:amd64 python3.12 python3.12-dev python3.12-minimal python3.12-venv
依存関係の修復・不要なパッケージ削除
sudo apt --fix-broken install
sudo apt autoremove
Pythonを再インストール
sudo apt install python3.12 python3.12-dev python3.12-venv libpython3.12-dev
解決。