Error: Command '['/path/to/env/bin/python3.7', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1

Solution 1:

I am using python3.9. The command below solved the issue for me:

sudo apt-get install python3.9-venv

Solution 2:

I realised that python3.7 comes with bionic and removed ppa:deadsnakes/ppa as well as python3.7. After installing it regularly, I got the following:

$ python3.7 -m venv v2
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: ['/home/.../v2/bin/python3.7', '-Im', 'ensurepip', '--upgrade', '--default-pip']

python3-venv was already installed, but python3.7-venv wasn't, and with that I could create the environment.

Solution 3:

Use this apt-get install python3.7-dev python3.7-venv to install python3.7-dev and python3.7-venv packages and you are good to go

Solution 4:

This error occurred to me in a very different scenario. Hope it ends up helping someone.

I was working on my ntfs drives and they were being auto-mounted at boot in /etc/fstab using ntfs-3g with root permissions by default.

When trying to create virtualenv it showed me the same error. This was fixed by adding uid and gid particular flags in /etc/fstab

UUID=<uuid> <mount-path> ntfs <other-flags>,uid=<uid of user>,gid=<gid of user> 0 0