I'm trying to set up a standard virtual-environment(venv) with python 3.7 on Ubuntu 18.04, with pip (or some way to install packages in the venv). The standard way to install python3.7 seems to be:
% sudo apt install python3.7 python3.7-venv
% python3.7 -m venv py37-venv
but the second command fails, saying:
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: ['/py37-venv/bin/python3.7', '-Im', 'ensurepip', '--upgrade', '--default-pip']
This is true; there is no ensurepip nor pip installed with this python. And I did install python3.7-venv
already (python3-venv
is for python3.6 on Debian/Ubuntu). I gather there has been some discussion about this in the python community because of multiple python versions and/or requiring root access, and alternate ways to install python modules via apt
or similar.
Creating a venv without pip (--without-pip
) succeeds, but then there's no way to install packages in the new venv which seems to largely defeat the purpose.
So what's the accepted "best practice" way to install and use python3.7 on 18.04 with a venv?
curl -O https://bootstrap.pypa.io/get-pip.py
and to install pip:sudo python get-pip.py
– Cordeliacordeliepip install virtualenv
and to use:virtualenv --python=<path/to/python/> /path/to/venv
andsource venv/bin/activate
. You should see the name of your virtual environment as (venv) in your prompt. – Cordeliacordelieapt install python3.7-distutils
in addition to installing python. But then they do work. – Amrpython3.7-venv
is mostly a copy ofpython3.6-venv
, including the systempip
check; however, the packagepython3.7-pip
doesn't exist for ubuntu bionic, leaving python 3.7 without a systempip
. Overall, this looks like an ubuntu issue to me and should be fixed. – Grath