DEV Community

hub
hub

Posted on

the difference between "virtualenv" and "-m venv" in creating Python Virtual environments

Sorry if I sound a bit foolish I'm confused about this: What's the difference between the two:

virtualenv myvenv

and

-m venv myvenv

The first one works well for me in creating virtual environments while the other does not.

I cd into my development directory and use virtualenv myvenv and…

Sorry if I sound a bit foolish. I'm confused about this: What's the difference between the two:

virtualenv myvenv

and

-m venv myvenv

The first one works well for me in creating virtual environments while the other does not.

I cd into my development directory and use virtualenv myvenv and it creates the virtual environment. But if I use -m venv myvenv, it just gives errors.

*answer: *
You would need to use

python -m venv myvenv

for that to work..., where

python -m calls the venv module as a script and passes myvenv as an argument to that script.

Coastatin answers in the same thread:

https://stackoverflow.com/questions/44091886/whats-the-difference-between-virtualenv-and-m-venv-in-creating-python-virt

**Venv **is a package shipped directly with python 3. So you don't need to pip install anything.

virtualenv instead is an independent library available at https://virtualenv.pypa.io/en/stable/ and can be installed with pip.

They solve the same problem and work in a very similar manner.

If you use python3 I suggest to avoid any "extra" dependencies and just stick with venv.

Your error is probably because you use Python2/pip2.

and furthermore we can read *the following: *
https://stackoverflow.com/questions/44091886/whats-the-difference-between-virtualenv-and-m-venv-in-creating-python-virt

I think the** virtualenv docs** explain this the best: ( https://virtualenv.pypa.io/en/stable/ )

  1. venv is a subset of virtualenv integrated into the standard library since Python 3.3. The subset meaning that only part of virtualenvs functionality is in venv:
  2. venv can be slower since it does not have the "app-data seed method". See more about virtualenv Seeders in the docs.
  3. venv can only be updated by upgrading the Python version, while virtualenv is updated using pip.
  4. venv is not extendable
  5. virtualenv has richer programmatic API (describe virtual environments without creating them). See the venv API here.
  6. venv cannot automatically discover arbitrarily installed python versions, while virtualenv does. This means, that with venv you have to specify the full path of the python executable, if you want to use some other python version than the first one in the PATH. With virtualenv, you can just give the version number. See python discovery in the virtualenv documentation.

and **Niko Föhr **continues: To me the differences are quite subtle and the only practical difference has been that venv is included in the standard library (since 3.3). I have been using python -m venv venv for a long time and have never needed an alternative.

cf. https://stackoverflow.com/questions/44091886/whats-the-difference-between-virtualenv-and-m-venv-in-creating-python-virt

Top comments (0)