環境
- Ubuntu 24.04
以下のコマンドはdockerのコンテナ内で実行しています。
$ docker run -it ubuntu:24.04 /bin/bash
# uname -a
Linux cf81d231b59a 5.15.153.1-microsoft-standard-WSL2 #1 SMP Fri Mar 29 23:14:13 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
# cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo
起きたこと
Ubuntuのpython3.12
パッケージをインストールしてPython環境を構築しました。
# apt install python3.12
# python3.12 --version
Python 3.12.3
ensurepip
モジュールを利用して、pip
コマンドをインストールしようとしましたが、ensurepip
モジュールは存在しませんでした。
# python3.12 -m ensurepip --upgrade
/usr/bin/python3.12: No module named ensurepip
python3.12-venv
パッケージをインストールすると、ensurepip
を利用することができます。しかし、Ubuntuではensurepip
は無効化されているため、結局pip
をインストールできませんでした。
# apt install python3.12-venv
# python3.12 -m ensurepip
ensurepip is disabled in Debian/Ubuntu for the system python.
Python modules for the system python are usually handled by dpkg and apt-get.
apt install python3-<module name>
Install the python3-pip package to use pip itself. Using pip together
with the system python might have unexpected results for any system installed
module, so use it on your own risk, or make sure to only use it in virtual
environments.
どうすればpip
をインストールできるか
- (A) 警告メッセージに書いてある通り
python3-pip
パッケージをインストールする - (B) https://bootstrap.pypa.io/get-pip.py からスクリプトをダウンロードして、
python get-pip.py
を実行する
参考にしたサイト