4

Some guides mention pyvenv (not pyenv) when talking about virtual environments such as the official Python tutorial. Others mention virtualenv such as in the Hitchhiker's Guide to Python. I've tried pyvenv and I think that it worked as you can see:

and these are the contents of ve directory:

So can pyvenv be used to create virtual environments? Does virtualenv do the same as pyvenv? Which one should better be used?

lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228
Ammar Alyousfi
  • 4,112
  • 5
  • 31
  • 42

3 Answers3

5

They are very much alike. The main difference is that virtualenv has been around for a long time, and can be used in most setups.

pyvenv, on the other hand, was designed for Python3, and ships with the standard library since version 3.4.

In other words, virtualenv is the classic choice, while pyvenv is a recent addition to the standard library. I suppose pyvenv will eventually replace virtualenv (as soon as Python 3 replaces Python 2 :P)

salezica
  • 74,081
  • 25
  • 105
  • 166
  • 4
    Almost true. `pyvenv` is not part of standard library while `venv` is since Python 3.3 as the official documentation says. – ElmoVanKielmo Nov 29 '16 at 15:34
  • Here's the link to the documentation of `venv`, for the record: https://docs.python.org/3/library/venv.html – naktinis Nov 29 '16 at 16:09
3

pyvenv is basically a wrapper around venv module which is part of standard library since Python 3.3 and is the recommended way of creating virtual enviromnents since then. And actually pyvenv wrapper is not so recommended. On Python >= 3.3 consider using venv module directly as described in linked docs. Older Python versions should use virtualenv to create virtual environments.

ElmoVanKielmo
  • 10,907
  • 2
  • 32
  • 46
1

How you create a virtual environment depends upon whether you are using Python 3 or 2.

  • virtualenv is a tool to create isolated Python environments. It can be used with Python 2 and 3.

  • pyvenv was introduced in Python 3.3, it was deprecated since Python 3.6 in favor of using python3 -m venv, and it is scheduled to disappear in Python 3.8.

As practical advice, use the following to create a virtual environment called venv depending on your Python version:

$ virtualenv venv # in Python 2 
$ python3 -m venv venv # Python 3

Regardless of which Python version you use, a folder venv containing the files of the virtual environment will be created.

lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228