4

Some things you should know before I ask my question:

  • I am utterly new to both Linux & Python, and have a hard time understanding official documentation and technical answers (but have a burning desire to deeply understand both)
  • I am running elementary OS 0.4.1 Loki
  • My Python 3 version is 3.5.2. When I search the online documentation on the venv module for python 3.5.2, I get the documentation for the 3.5.6 version. I don't understand why there is no documentation for the .2 version.

So, here's my problem. I was trying to create a virtual environment using venv and proceeded thusly:

According to Python's 3.5.6 venv module documentation, a virtual environment is created using the command pyvenv /path/to/new/virtual/environment. I tried that command and got:

The program 'pyvenv' is currently not installed. You can install it by typing: sudo apt install python3-venv

I then searched documentation for newer Python versions and tried the new venv command python3 -m venv /path/to/new/virtual/environment and got the following result:

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

In both cases, the solution seems to be to install python3-venv. My question is: What exactly am I installing by installing python3-venv: Isn't venv already part of the Standard Library? Furthermore, why do I have to install it via apt-get if it is a Python module? It is my understanding that standard library modules are imported, not installed; and that modules external to the standard library are installed via pip. Related to this, why is ensurepip not available?

Second part of my question: if installing python3-venv is the way to go, what is the proper way to create a virtual environment using venv in Python 3.5.2: pyvenv my_virtual_environment or python3 -m venv my_virtual_environment?

Ken White
  • 123,280
  • 14
  • 225
  • 444
simón
  • 41
  • 2
  • 1
    Was just about to ask the very same question. I have no idea why we should have to have to install python3-venv to use this "core" module. In that case what makes venv superior to virtualenv? You have to install both. – Ben Ogorek Oct 12 '19 at 17:38

1 Answers1

2

Don't worry about the documentation not matching the micro version number – increments in that place are only for bugfixes, so the documentation stays the same.

Your question is interesting since venv is indeed not an optional module. My guess is that the Python version shipped with your OS (or that you installed yourself) seems to come with a stripped down or no standard library. For instance, the python3.5-minimal package doesn't appear to have it. Does your Python have the other modules in the standard library?

Edit: See also this question.

Installation can be described as "putting files onto your computer, in the right place". Importing a module, however, means that you tell Python to make available some functionality. To import a module, it must be installed (e.g. in /usr/lib/python3.5 for Python 3 on my computer), and one method for installing additional modules is via apt.

The python3 -m venv my_virtual_environment method should work in 3.5 as well and is the future-proof version, so you should probably go with that.

nnnmmm
  • 7,964
  • 4
  • 22
  • 41
  • Thanks for your reply @nnnmmm!! I had no idea about the python3.5-minimal package. I followed the link, clicked on the amd64 and found this list of files: /usr/bin/python3.5 /usr/bin/python3.5m /usr/share/binfmts/python3.5 /usr/share/doc/python3.5-minimal/README.Debian /usr/share/doc/python3.5-minimal/changelog.Debian.gz /usr/share/doc/python3.5-minimal/copyright /usr/share/man/man1/python3.5.1.gz /usr/share/man/man1/python3.5m.1.gz So I guess to verify wheter or not venv is included in python3.5-minimal I would have to search those directories, is that correct? – simón Aug 17 '18 at 21:47
  • I can't answer your question on other modules included in the standard library, because I don't know how to look. Would you mind explaining it to me? Thanks again :) – simón Aug 17 '18 at 21:49
  • I have another question, sorry! You said apt is one method for installing additional modules; what other methods are there? – simón Aug 17 '18 at 21:52
  • You can test by simply opening Python and typing `import `. And these are already all the files contained in the python3.5-minimal package - it does not contain any modules. However, I'm not saying that it is the case that you have (only) that specific package installed, just that that could be one way how you might end up with a situation like yours. pip or conda are other methods. I'm going to bed now, so I can't answer any more questions until tomorrow, sorry! – nnnmmm Aug 17 '18 at 21:58