0
0

Ubuntuの`python3.12`パッケージには`ensurepip`モジュールが存在しない

Posted at

環境

  • 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を実行する

参考にしたサイト

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