Creating your first venv

Creating an environment is quite easy. The basic command comes down to pyvenv PATH_TO_THE_NEW_VIRTUAL_ENVIRONMENT, so let's give it a try. Note that this command works on Linux, Unix, and Mac; the Windows command will follow shortly:

pyvenv test_venv

. ./test_venv/bin/activate

(test_venv) #

Some Ubuntu releases (notably 14.04 LTS) maim the Python installation by not including the full pyvenv package with ensurepip. The standard workaround is to call pyvenv --without-pip test_env, which requires a manual pip installation through the get_pip.py file available on the <color name="red50">pip</color> home page.

This creates an environment called test_venv, and the second line activates the environment.

On Windows, everything is slightly different but similar overall. By default, the pyvenv command won't be in your PATH, so running the command is slightly different. The three options are as follows:

Add the Python\Tools\Scripts\ directory to your PATH

Run the module:

python -m venv test_venv

Run the script directly:

python Python\Tools\Scripts\pyvenv.py test_venv

For convenience, I would recommend that you add the Scripts directory to your PATH anyhow, since many other applications/scripts (such as pip) will be installed there as well.

Here is the full example for Windows:

C:\envs>python -m venv test_venv
C:\envs>test_venv\Scripts\activate.bat
(test_venv) C:\envs>

When using Windows PowerShell, the environment can be activated by using test_venv\Scripts\Activate.ps1 instead. Note that you really do need backslashes here.

results matching ""

    No results matching ""