Python3で仮想環境作成時にFailing command: ['/home/user/venv/bin/python', '-Im', 'ensurepip', '--upgrade', '--default-pip']が出た時の対処方法
python3がインストールされているのに仮想環境(venv)作成時に以下のエラーが発生する場合があります。
# python -m venv venv
The virtual environment was not created successfully because ensurepip is not
available. On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.
apt-get install python3-venv
You may need to use sudo with that command. After installing the python3-venv
package, recreate your virtual environment.
Failing command: ['/root/fastapi/fastapi/bin/python', '-Im', 'ensurepip', '--upgrade', '--default-pip']
今回のその場合の解決方法を紹介します。
解決方法
エラーメッセージにある通り、python-venvをインストールすれば解決します。
apt install python3-venv
3.9系はきちんとバージョンを指定する必要がある。
apt install python3.9-venv
python-venvのインストールログを確認する。
# apt install python3.9-venv
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
python3.9-venv
0 upgraded, 1 newly installed, 0 to remove and 7 not upgraded.
Need to get 5,452 B of archives.
After this operation, 27.6 kB of additional disk space will be used.
Setting up python3.9-venv (3.9.5-3ubuntu0~20.04.1) ...