Virtual Env Support

New in PTVS 2.0 Alpha

clip_image001

Virtual environments can be now be configured per-project and quickly activated using your project’s “Virtual Environments” node in Solution Explorer.  To create a new virtual environment you can right click on the Virtual Environments tree node and select “Create Virtual Environment…” 

clip_image002

You will be prompted for the base interpreter to be used. This is selected from one of the available interpreters configured in Tools->Options->Python Tools->Interpreters and includes all interpreters automatically discovered by PTVS.  PTVS will use this interpreter installation to create the new virtual environment.  For this to succeed the interpreter will already need to have had virtualenv installed.

Next you can specify the location where the virtual environment will be created; by default this is your project directory.  Finally, give a name to the virtual environment – this is the name of the folder that will be created on disk. 

clip_image003

Once you click OK, PTVS will create the new virtual environment and add it to Solution Explorer.  If you have an existing virtual environment you’d like to use with your project you can choose “Add Virtual Environment…” instead and provide the directory where you’ve already created the virtual environment. 

PTVS also supports track the packages which are installed into your virtual env and let you install new packages without leaving the IDE.  To install a package right click on the virtual environment and select “Install Python Package…” 

clip_image004

You will be prompted for the package name to be installed:

clip_image005

Type the name of the package you’d like to install and click OK.  PTVS will use PIP to install the package and the output of the installation will be printed into the output window.  After installing a package, you’ll see that it is listed below the virtual environment in Solution Explorer:

clip_image006

To uninstall a package, right click on it and select “Uninstall Python Package”. The package will be removed from the virtual environment and the result of uninstalling the package will be shown in the output window.

Finally, once you’ve configured your virtual environments, you can quickly switch between different Python interpreter configurations.  To choose your current virtual environment, right click on it and choose “Activate Virtual Environment”. 

clip_image007

Activating the virtual environment will cause PTVS to use the interpreter and libraries that are in the virtual environment when running or debugging.  To switch back to the default libraries, you can deactivate a virtual environment.  This will leave your project configured against the base interpreter of the virtual environment.  The currently active virtual environment will be highlighted in Solution Explorer with a bolded name and a small overlay icon:

clip_image008

In PTVS 2.0 Alpha there are still a few known issues with virtual environment support, as well as some features yet to be implemented.  We’d appreciate any feedback about what else you’d like to see supported with virtual environment, so please vote for the issues below or let us know if we missed anything.

Intellisense is currently not enabled against the packages installed into a virtual environment

Python 3.3’s “venv” is currently not supported

Enable/disable virtual env are not dynamically being enabled/disabled based upon the active virtual environment

Virtual env’s should support creating REPL’s

Virtual env should support searching PyPi

virtual env should automatically open output window

Last edited Mar 8 at 1:06 AM by Zooba, version 5

Comments

No comments yet.