# 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
python3-venvのインストールログを確認する。
# apt-get install python3-venv
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libpython3.8 libpython3.8-minimal libpython3.8-stdlib python-pip-whl
python3.8 python3.8-minimal python3.8-venv
Suggested packages:
python3.8-doc binutils binfmt-support
The following NEW packages will be installed:
python-pip-whl python3-venv python3.8-venv
The following packages will be upgraded:
libpython3.8 libpython3.8-minimal libpython3.8-stdlib python3.8
python3.8-minimal
5 upgraded, 3 newly installed, 0 to remove and 171 not upgraded.
Need to get 1,812 kB/8,116 kB of archives.
After this operation, 2,404 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://jp.archive.ubuntu.com/ubuntu focal-updates/universe amd64 python-pip-whl all 20.0.2-5ubuntu1.6 [1,805 kB]
Get:2 http://jp.archive.ubuntu.com/ubuntu focal-updates/universe amd64 python3.8-venv amd64 3.8.10-0ubuntu1~20.04.2 [5,444 B]
Get:3 http://jp.archive.ubuntu.com/ubuntu focal/universe amd64 python3-venv amd64 3.8.2-0ubuntu2 [1,228 B]
Fetched 1,812 kB in 0s (10.2 MB/s)
(Reading database ... 108109 files and directories currently installed.)
Preparing to unpack .../0-libpython3.8_3.8.10-0ubuntu1~20.04.2_amd64.deb ...
Unpacking libpython3.8:amd64 (3.8.10-0ubuntu1~20.04.2) over (3.8.5-1~20.04.2) ...
Preparing to unpack .../1-python3.8_3.8.10-0ubuntu1~20.04.2_amd64.deb ...
Unpacking python3.8 (3.8.10-0ubuntu1~20.04.2) over (3.8.5-1~20.04.2) ...
Preparing to unpack .../2-libpython3.8-stdlib_3.8.10-0ubuntu1~20.04.2_amd64.deb ...
Unpacking libpython3.8-stdlib:amd64 (3.8.10-0ubuntu1~20.04.2) over (3.8.5-1~20.04.2) ...
Preparing to unpack .../3-python3.8-minimal_3.8.10-0ubuntu1~20.04.2_amd64.deb ...
Unpacking python3.8-minimal (3.8.10-0ubuntu1~20.04.2) over (3.8.5-1~20.04.2) ...
Preparing to unpack .../4-libpython3.8-minimal_3.8.10-0ubuntu1~20.04.2_amd64.deb ...
Unpacking libpython3.8-minimal:amd64 (3.8.10-0ubuntu1~20.04.2) over (3.8.5-1~20.04.2) ...
Selecting previously unselected package python-pip-whl.
Preparing to unpack .../5-python-pip-whl_20.0.2-5ubuntu1.6_all.deb ...
Unpacking python-pip-whl (20.0.2-5ubuntu1.6) ...
Selecting previously unselected package python3.8-venv.
Preparing to unpack .../6-python3.8-venv_3.8.10-0ubuntu1~20.04.2_amd64.deb ...
Unpacking python3.8-venv (3.8.10-0ubuntu1~20.04.2) ...
Selecting previously unselected package python3-venv.
Preparing to unpack .../7-python3-venv_3.8.2-0ubuntu2_amd64.deb ...
Unpacking python3-venv (3.8.2-0ubuntu2) ...
Setting up libpython3.8-minimal:amd64 (3.8.10-0ubuntu1~20.04.2) ...
Setting up python3.8-minimal (3.8.10-0ubuntu1~20.04.2) ...
Setting up python-pip-whl (20.0.2-5ubuntu1.6) ...
Setting up libpython3.8-stdlib:amd64 (3.8.10-0ubuntu1~20.04.2) ...
Setting up python3.8 (3.8.10-0ubuntu1~20.04.2) ...
Setting up libpython3.8:amd64 (3.8.10-0ubuntu1~20.04.2) ...
Setting up python3.8-venv (3.8.10-0ubuntu1~20.04.2) ...
Setting up python3-venv (3.8.2-0ubuntu2) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for mime-support (3.64ubuntu1) ...
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.
Get:1 http://jp.archive.ubuntu.com/ubuntu focal-updates/universe amd64 python3.9-venv amd64 3.9.5-3ubuntu0~20.04.1 [5,452 B]
Fetched 5,452 B in 0s (26.0 kB/s)
Selecting previously unselected package python3.9-venv.
(Reading database ... 109292 files and directories currently installed.)
Preparing to unpack .../python3.9-venv_3.9.5-3ubuntu0~20.04.1_amd64.deb ...
Unpacking python3.9-venv (3.9.5-3ubuntu0~20.04.1) ...
Setting up python3.9-venv (3.9.5-3ubuntu0~20.04.1) ...
root@118-27-103-174:~# apt install python3.9-venv
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3.9-venv is already the newest version (3.9.5-3ubuntu0~20.04.1).
0 upgraded, 0 newly installed, 0 to remove and 7 not upgraded.