virtualenv: Error creating virtualenv with python3.6

Earlier today I installed python3.6 on my debian machine. Python3.6 was made available in buster distribution. When I try to create a virtualenv with python3.6.

python3.6 -m venv venv

gives the following error.

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/float/test/t/bin/python3.6’, ‘-Im’, ‘ensurepip’, ‘–upgrade’, ‘–default-pip’]

I do have python3-venv (3.5.3-1) installed. Why do I get this error? If I run the command

py3 -Im ensurepip --upgrade --default-pip

it says

/usr/bin/python3.6: No module named ensurepip

I don’t have trouble creating virtualenvs using the default python3 version (3.5.3).

Also , I noticed that I can create a virtualenv as follows:

virtualenv -p python3.6 venv

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 5
  • Comments: 24 (1 by maintainers)

Most upvoted comments

The original poster’s problem is due to not having the ‘python3.6-venv’ package installed, which can be verified using Docker if you don’t have access to a buster Debian:

$ docker run --rm -it debian:buster /bin/bash
$ apt update
...
$ apt install python3.5 python3.6 python3.5-venv
...
$ python3.6 -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: ['/venv/bin/python3.6', '-Im', 'ensurepip', '--upgrade', '--default-pip']
$ rm -rf venv
$ apt install python3.6-venv
...
$ python3.6 -m venv venv
... success

Install ‘python3.6-venv’, and it should work.

Wrongly configured locale can also induce this problem, as this answer solves my problem that produces the same error message as OP.

Try execute:

export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
sudo dpkg-reconfigure locales

Hi,

virtualenv and python3 venv own module are 2 totally different projects/things.

venv is doing the same than virtualenv but is directly integrated in python3 itself. virtualenv is the historic project basically (and normally should not be used with python3 while there is venv).

Based on your input I’d say python3-venv may be to reinstall (sudo apt-get reinstall python-venv or something similar) on your side. But I can be wrong. Anyway this looks like all debian related I’m pretty sure.

So may you close the issue ? (I’m not maintainer here) regards.

Wow, it didn’t occur to me at all that there would be a version specific -venv package. Installing this did the trick.

@gst and @eukaryote Thank you so much for spending your time on this issue.

Just leaving a comment here, for the ones who arrive after me, googling for the same problem:

the same applies to 3.7 of python, you have to install python3.7-venv, that is apt-get install python3.7-venv

Just FYI, the above solution does not in fact work for python 3.7. apt install python3.7 python3.7-venv on a stock buster docker image still produces a broken virtualenv (“ensurepip is not available”). However, after apt install python3-venv (which needlessly installs all of python3.6), you can create a working python 3.7 venv including a proper 3.7 pip, with python3.7 -m venv myvenv. So the complete working command set is this:

sudo apt install python3.7 python3-venv python3.7-venv # all three are required
python3.7 -m venv myvenv
. myvenv/bin/activate

(btw, note that all python3.7-venv installs is a dummy system ensurepip module.)

I’m on Debian testing/buster and I’m having this same issue, while both python3.6-venv and python3-venv are both installed.

Fisrt I’ve installed with sudo apt install python3-venv and had the same problem and, it was solved by doing: sudo apt install python3.6-venv

Wow, installing the specific version of venv worked for me. In my case python3.8-venv.

Thanks @jrperin

only one datapoint, but messing about with a fresh virtualbox ubuntu bionic, i found that apt install python3.6-venv still left me with a broken python3.6 -m venv, but running apt install python3-venv fixed it.