wasp256
wasp256

Reputation: 6242

python3.6 fails when creating venv

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']

Upvotes: 5

Views: 4043

Answers (2)

JohnC
JohnC

Reputation: 3257

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

Upvotes: 2

Martijn Pieters
Martijn Pieters

Reputation: 1121972

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.

Upvotes: 5

Related Questions