Wing Tips: Using virtualenv with Wing Python IDE

Feb 05, 2020


In this Wing Tip we'll take a look at how to configure your project to use a virtualenv Python.

Configuring an Existing Project

For an existing Wing project, you can specify a virtualenv as the Python Executable in Project Properties (from the Project menu) in one of two ways:

(1) Select Command Line and enter the full path to the virtualenv's python or python.exe. This executable both activates the env and runs Python, so all the code Wing launches will run in the environment.

When in doubt about which path to use, run your virtualenv outside of Wing and inspect the value of sys.executable after import sys. That is the value you want to use.

(2) Select Activated Env and enter the full path to the virtualenv's activate or activate.bat:

/images/blog/virtualenv/properties.png

The drop down menu next to the entry area lists discovered environments and those which have been used recently:

/images/blog/virtualenv/recent-envs.png

Activated virtualenvs can be used in the same way in other settings where a Python Executable can be specified, for example for Launch Configurations and in a Remote Host configuration.

Creating New Projects

There are two options available for virtualenv, when creating a new project from the Project menu: (1) Creating a new virtualenv and new Wing project at the same time, or (2) Creating a new Wing project that uses an existing virtualenv.

Creating a New virtualenv

To create a new virtualenv along with your project, select New Project from the Project menu, select or created your source directory, and press Next. On the second screen, choose Create New Environment and select Virtualenv as your environment type. You will then need to enter the name for the virtualenv, select a parent directory where the virtualenv's directory will be written, and optionally specify packages to install and/or the base Python Executable to use. For example:

/images/blog/virtualenv/new-project-new.png

Wing will create the virtualenv, install packages, and then configure and save a project file. You can immediately start working in your new virtualenv, which Wing automatically activates for you whenever you have the project open.

Using an Existing virtualenv

To use an existing virtualenv, select New Project from the Project menu, select or create your source directory, and press Next. On the second screen, select Use Existing Python and select Activated Env under Python Executable. You can then select a recent or found environment from the drop down or manually enter your activation command:

/images/blog/virtualenv/new-project-existing.png

For some additional details, see Using Wing with virtualenv.

Package Management

Once you've configured your project, you can use the Packages tool in the Tools menu to list, add, remove, or update packages. We will cover this in a future Wing Tip. See Package Manager for details.



That's it for now! We'll be back soon with more Wing Tips for Wing Python IDE.

As always, please don't hesitate to email support@wingware.com if you run into problems or have any questions.



Share this article: