Ammar Alyousfi
Ammar Alyousfi

Reputation: 4372

Do I use `pyvenv` or `virtualenv` for creating a virtual environment?

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?

Upvotes: 4

Views: 6489

Answers (3)

lmiguelvargasf
lmiguelvargasf

Reputation: 69755

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.

Upvotes: 1

ElmoVanKielmo
ElmoVanKielmo

Reputation: 11290

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.

Upvotes: 3

salezica
salezica

Reputation: 76929

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)

Upvotes: 6

Related Questions