Using Wing with Anaconda

Index of All Documentation » How-Tos » How-Tos for Containers »


Wing Pro Screenshot

Wing is a Python IDE that can be used to develop, test, and debug Python code run with the Anaconda Distribution of Python.

Two versions of Wing are appropriate for use with this document: Wing Pro is the full-featured Python IDE for professional developers, and Wing Personal is a free alternative with reduced feature set.

If you do not already have Wing installed, download it now.

This document describes how to configure Wing for use with Anaconda Python. To get started using Wing as your Python IDE, please refer to the tutorial in Wing's Help menu or read the Quickstart Guide.

Configuring the Environment

To use the Anaconda with Wing, simply set the Python Executable used in your Wing project to Anaconda's python or python.exe. How you do this depends on whether you are creating a new project or have an existing project that you want to modify.

New Projects

To create a new Wing project that uses Anaconda, select New Project from the Project menu and then under Python Executable select Custom and enter the full path to Anaconda's python or python.exe. In many cases, Wing will automatically find Anaconda and include it in the drop down menu to the right of the entry area that enables after Custom is chosen.

If Anaconda does not appear in Wing's list of available Python installations, and you don't know the full path to use, then you can start Anaconda from the command line outside of Wing and use the value printed by the following, when run interactively:

import sys
print(sys.executable)

In most cases, setting Python Executable is all that you need to do. Wing will start using your Anaconda installation immediately for source intelligence, for the next debug session, and in the integrated Python Shell after it is restarted from its Options menu.

Existing Projects

To change an existing project to use Anaconda Python, the steps are the same as above except that the change is made under Project Properties in the Project menu.

Virtualenv

If you are using virtualenv with Anaconda, the steps are also the same as above, except that you use the full path of the virtualenv's python.exe or python instead. When in doubt, you can print sys.executable as already described to find the correct full path to use in Wing's Python Executable configuration.

Fixing Import Errors

On Windows, Anaconda may fail to load DLLs when its python.exe is run directly from the command line or within Wing. This is due to the fact that by default the Anaconda installer no longer sets the PATH that it needs to run, in order to avoid conflicting with different Python installations on the same system. A typical error message looks like this:

Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control).  Otherwise reinstall numpy.

Original error was: DLL load failed: The specified module could not be found.

The exact message you see will vary depending on which packages you are using, or you may not run into this at all if you are not using packages that affected by it.

There are several possible solutions to this problem. The recommended solutions are more work, but the easier solutions may cause problems if you have multiple Python installations on your system.

Simple Solution

A simple solution to fix this problem is to run Scripts\activate (located within your Anaconda installation) on the command line, and then start Wing from within the activated environment, for example with c:\Program Files (x86)\Wing Pro 7\bin\wing.exe. This causes Wing to inherit the necessary PATH that was set up by Anaconda's activate script.

This solution works well if you will be using the same Anaconda installation for all projects that you open in a session. If you change to projects that use a different Python installation, you will need to quit and restart Wing in the correct environment.

Recommended Solutions

Our recommended solutions require a bit more work up front, but once in place they automatically set the necessary PATH without the potential for polluting other Python installations with unwanted environment.

A good one-time fix is to create a small wrapper script called wrap_anaconda.bat and place the following into it:

@echo off
call %USERPROFILE%\Anaconda3\Scripts\activate
python %*

You will need to change the second line to match where Anaconda is installed on your system.

Then set Python Executable in Wing's Project Properties to the full path of this batch file. This sets up the necessary environment and then runs Anaconda's Python. No other configuration is necessary, and this script can also be used on the command line or in other IDEs.

A similar solution that does not require creating a wrapper script is to set the necessary PATH in Wing's Project Properties, from the Project menu. Add the following to Environment under the Environment tab:

ANACONDA_DIR=${USERPROFILE}\Anaconda3
PATH=${PATH};$(ANACONDA_DIR);${ANACONDA_DIR}\DLLS;${ANACONDA_DIR}\Library;
  ${ANACONDA_DIR}\Library\bin;${ANACONDA_DIR}\Scripts;${ANACONDA_DIR}\mingw-w64\bin

You may need to change the value of ANACONDA_DIR to match where Anaconda is installed on your system.

Both of these solutions work well if there are multiple Python installations on your system, because it ensures that the correct PATH is always set when the project is open, allowing other projects to use a different environment.

Discouraged Solution

Another easy but potentially problematic solution is to select the Add Anaconda to my PATH environment variable in Anaconda's installer. This sets the necessary PATH system-wide. However, this is not recommended because it will cause serious problems if other Python installations are added later.

Related Documents

For more information see: