Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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']
like image 252
wasp256 Avatar asked May 04 '18 07:05

wasp256


People also ask

Can you specify Python version in venv?

Create the virtual environment while you specify the version of Python you wish to use. The following command creates a virtualenv named 'venv' and uses the -p flag to specify the full path to the Python3 version you just installed: You can name the virtualenv anything you like.

Is venv deprecated?

Virtualenv has been deprecated in Python 3.8.


1 Answers

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.

like image 52
Martijn Pieters Avatar answered Oct 03 '22 06:10

Martijn Pieters