<type>how-to</type>
<domain>howtos</domain>
<id>anaconda</id>
<title>Using Wing with Anaconda</title>
<date>$Date: 2012-11-15 15:25:42 -0500 (Thu, 15 Nov 2012) $</date>
<version>$Revision: 27651 $</version>
<product>per+</product>

.. image:: /images/screenshots/wing7-screenshot-linen.png
  :alt: Wing Screen Shot
  :width: 574
  :height: 423
  :popup: 1

`Wing <https://wingware.com>`__ is a Python IDE that can be used to develop, test, and
debug Python code run with the `Anaconda Distribution
<https://www.anaconda.com/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 <https://wingware.com/downloads>`__.

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 <ref:howtos/quickstart>`__.

Configuring the Environment
---------------------------

To use the `Anaconda Distribution <https://www.anaconda.com/distribution/>`__ of Python
with Wing, set the ``Python Executable`` in Wing's ``Project Properties``, from the
``Project`` menu, to the full path to Anaconda's ``python`` or ``python.exe``. 

If you don't know the full path but can start Anaconda from the command line outside of
Wing, use the value printed by the following, when run interactively::

  import sys
  print(sys.executable)

In many cases, that 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 once from its ``Options`` menu.

Fixing Import Errors
--------------------

On Windows, the Anaconda installer no longer sets the ``PATH`` it needs to run by default,
in order to avoid conflicting with different Python installations on the same system.
This means that, unless ``PATH`` is set manually, Anaconda will fail to import some 
of its own modules because it cannot find necessary DLLs. 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.

This occurs even when Anaconda's ``python.exe`` is run from the command line outside
of any IDE.

There are several possible solutions to this problem, when using Anaconda with Wing.

Recommended Solution
....................

Our recommended solution is to create a small wrapper script called ``wrap_anaconda.bat``
and place the following into it::

  @echo off
  set ANACONDA_DIR=%USERPROFILE%\Anaconda3
  set PATH=%PATH%;%ANACONDA_DIR%;%ANACONDA_DIR%\DLLS;%ANACONDA_DIR%\Library;%ANACONDA_DIR%\Library\bin;%ANACONDA_DIR%\Scripts;%ANACONDA_DIR%\mingw-w64\bin
  %ANACONDA_DIR%\python.exe %*

You may need to change the value of ``ANACONDA_DIR`` 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.

Other Solutions
...............


.. raw:: html

  <b><u>Set PATH in Project Properties</u></b>

You can also 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.

This approach works 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 set a different value.

.. raw:: html

  <b><u>Run activate Before Starting Wing</u></b>

Running ``Scripts\activate`` from your Anaconda installation sets the necessary values in
``PATH``. If you invoke this on the command line and then start Wing from the command line
as well, by invoking the ``bin\wing.exe`` in your Wing installation, then Wing will
inherit the ``PATH``.

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

.. raw:: html

  <b><u>Install Anaconda so it Adds to PATH</u></b>

The Anaconda installer provides an option ``Add Anaconda to my PATH environment variable``
which can be used if you plan to only have one installation of Python on your system. This
adds the necessary directories to the default value for ``PATH`` so no other configuration
is necessary. It will cause problems if other Python installations are added later.

Related Documents
-----------------

For more information see:

* `Quickstart Guide <ref:howtos/quickstart>`__ contains additional basic information
  about getting started with Wing.
  
* `Tutorial <ref:intro/tutorial>`__ provides a gentler introduction to Wing's features.

* `Wing Reference Manual <ref:manual>`__ documents Wing in detail.

