5

I'm trying to setup a venv with Python3.6 but receive the error that was already mentioned in various other posts such as here. Unfortunately, none of the proposed solutions worked.

I have installed the necessary packages

$ sudo apt install python3.6-venv
...
$ dpkg -l | grep "python3.6-venv"
ii  python3.6-venv                              3.6.5-5~16.04.york0                          amd64        Interactive high-level object-oriented language (pyvenv binary, version 3.6)

I also installed python3-venv (which is for python 3.5). When now trying to setup the venv I receive

python3.6 -m venv test
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/User/Python/test/bin/python3.6', '-Im', 'ensurepip', '--upgrade', '--default-pip']
wasp256
  • 5,943
  • 12
  • 72
  • 119

2 Answers2

5

On Debian / Ubuntu systems, python -m venv has been disabled, because the way the virtualenv tool bundles dependencies violates the DFSG and Debian policy against including code not built from source available within Debian.

Instead, on such systems you should always use the pyvenv* commands; there is a pyvenv-3.y versioned script specific to each Python version. In your case, use

pyvenv-3.6 test

and this then runs venv in such a way that the required packages are installed in a manner compliant with Debian policies.

Also see the /usr/share/doc/pyenv-3.6/python3.6-venv file installed with the pyvenv-3.6 package.

If this still produces a warning, please file a ticket with the Ubuntu package maintainers; the deprecation warning is new in Python 3.6 and Ubuntu should either disable that warning in their packaging, or fix the ensurepip issue directly in the python -m venv use case. If pyvenv-3.6 is broken outright (doesn't produce a valid virtualenv), then you should definitely file a ticket. See the bug tracker for the python-3.6 source package.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • 1
    when using `pyvenv-3.6` I receive the warning (and then the original error as above): `WARNING: the pyenv script is deprecated in favour of `python3.6 -m venv`` – wasp256 May 04 '18 at 07:41
  • @wasp256: that's something for the debian packagers to fix; as long as it produces a working virtualenv you are good. – Martijn Pieters May 04 '18 at 07:45
  • The problem is, it doesn't. There's no activation file in `test/bin`... – wasp256 May 04 '18 at 07:48
  • @wasp256: trying to see what the debian maintainers have to say about this. – Martijn Pieters May 04 '18 at 07:56
  • @wasp256: the [Ubuntu bugtracker for the Python 3.6 packages](https://launchpad.net/ubuntu/+source/python3.6/+bugs) makes no mention of this issue yet. I don't see any patches in the packaging that would disable the warning though, making it less likely that you are running a different `pyenv-3.6` (not packaged by Ubuntu), but you may want to check for that. In the meantime, it is probably worth filing a bug with Ubuntu. I do not currently have easy access to a VM to test this myself, sorry. – Martijn Pieters May 04 '18 at 08:56
  • Hmm, I did notice I had a typo in the command. It should be `pyvenv`, not `pyenv`. If you copied the wrong command from my answer, could you please try again? Sorry about that! – Martijn Pieters May 04 '18 at 08:58
  • Nah I noticed that and picked the right one :) so still difference – wasp256 May 04 '18 at 09:01
2

Ubuntu 18.10, Python 3.7.3

sudo apt install python3.7-venv
python -m venv ./venv

This fixed the problem for me. .venv now contains lots of files eg .venv/bin/activate

JohnC
  • 2,687
  • 1
  • 22
  • 30