1

I am using the Ubuntu on Windows App running on Windows Subsystem for Linux. So an initial question is if Python virtual environments is supported. Given my as yet limited understanding of Python virtual environments I would think that they are supported in the Ubuntu on Windows App. Here is the version info:

Windows Ubuntu App 1804.2019.521.0

Ubuntu release 18.04 (bionic)

Python Version 3.6.7 (as best I remember this was installed by default).

My motivation for wanting to use venv is this reddit post:

venv by nature of being part of Python itself has access to the internals of Python which means it can do things the right way with far fewer hacks... ...So venv can be thought of virtualenv done right, with the blessing and support of the Python developers.

Similar questions came up when I entered my question, but I didn't find one that solved my problem.

One post:

Since you specifically installed python3.6 instead of Ubuntu's default python3 version, which is python3.5, you have to install python3.6-venv instead of python3-venv since that would resolve to python3.5-venv. To do so, you can use sudo apt install python3.6-venv

Another post from 01/2018 said that python3.6 -m venv myvenv worked after reinstalling Python3.6.4. I'm avoiding re-installation for the time being.

Here is what I tried to create a virtual environment:

1) Opened Ubuntu

2) Went to the directory where I want to create the virtual environment.

 /home/dgrucza/python-virtual-environments

3) Entered python3 -m venv env This returned the following:

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/dgrucza/python-virtual-environments/evn/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']

4)Tried to install venv by entering sudo apt-get install python-venv After entering my password at the prompt this returned the following:

Reading package lists... Done Building dependency tree Reading state information... Done Package python3-venv is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source

E: Package 'python3-venv' has no installation candidate

5) Also tried entering python3.6 -m venv myenv, but received the same message.

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/dgrucza/myenv/bin/python3.6', '-Im', 'ensurepip', '--upgrade', '--default-pip']

  • 2
    For the system's default instance of Python 3, you should just need to install python3-venv. I don't expect any problems or conflicts/confusions if you don't have any custom Python versions installed. So do you have that already and it doesn't work? If so, please provide what exactly happens instead, like complete output and error messages. – Byte Commander Oct 21 '19 at 20:56
  • I've added the info you asked for. As best I remember my installation of Ubuntu is as it was when I installed it except for a few folders that I added in my home directory. – DavidG Oct 21 '19 at 21:56
  • 1
    Do you have the Universe repositories enabled? If not, that'll be one of the problems. – Thomas Ward Oct 21 '19 at 22:47
  • I executed sudo add-apt-repository universe and got this response: 'universe' distribution component is already enabled for all sources. – DavidG Oct 22 '19 at 16:12
0

What I did so far:

  1. Open Terminal
  2. Go to desired directory
  3. Type python3 -m venv name_of_virtual_env

If it doesn't work, could you please update your question to show the output of the Terminal?
EDIT
I just tested venv install on a virtual machine Lubuntu 19.04:
sudo apt install python3-venv
I could then create a virtual environment with above-mentionned command. However I already had Spyder3 installed so some dependencies could have come with it.
And as suggested by Thomas Ward, I share my sources:
Software sources

  • Thanks. I should know better by now. I've added this info to my question. – DavidG Oct 21 '19 at 21:53
  • The weird point if that "sudo apt-get install python-venv" doesn't work. Would you please try it again after typing "sudo apt update"? ANd if it still doesn't work, would you give a change to installing Spyder3 (a Python IDE) first and try again with python-venv? – FloT Oct 22 '19 at 7:24
  • 1
    I ran sudo apt update' followed by 'sudo apt upgrade, and the sudo apt install python3-venv ran successfully as did sudo python3 -m venv env. – DavidG Oct 22 '19 at 16:36
  • Should I summarize this in another answer so it is more readable? – DavidG Oct 22 '19 at 16:38
  • I should have know to update everything, but I'm still new to Ubuntu and Linux. It would be good to know conceptually what was preventing installation of venv. – DavidG Oct 22 '19 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.