<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>pro+</product>

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

`Wing Pro <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.

If you do not already have Wing Pro installed, `download it now <https://wingware.com/downloads/wingpro>`__.

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 Your Project
------------------------

To use Anaconda with an existing Wing project, simply set the ``Python Executable`` in 
``Project Properties`` to the interpreter that you want to use. There are several options for
this:

**Command Line** can be selected to enter the full path to Anaconda's ``python.exe`` or
``python``. In many cases, Wing will automatically find Anaconda and include it in the
drop down menu to the right of the file selector shown for this option. The Python
executable for Anaconda is typically located at the top level of the installation on
Windows and in the ``bin`` sub-directory on other OSes. Another way to find the correct
full path to use is to start Anaconda outside of Wing and then type the following:

.. python::

  import sys
  print(sys.executable)

**Activated Env** can be selected to use an existing environment created with ``conda
create`` or virtualenv. This should be the command that activates the environment, for
example ``activate venv1``.  In this case, Wing starts Python by running ``python`` in that
environment.  If Anaconda is installed in a default location, Wing will find
your existing environments, which can be selected with the drop down menu to the right of
this field.

Note that using ``Activated Env`` does not work if the full path to 
Anaconda's ``activate`` contains spaces.  In that case, use ``Command Line`` option
instead as described above.

If you are creating a new Wing project and want to use Anaconda, select ``New Project``
from the ``Project`` menu and configure ``Python Executable`` in the ``New Project``
dialog in the same way as described above.  Note that you can create a new Anaconda
environment from the ``New Project`` dialog by selecting ``Create New Environment``
on the second dialog page and choosing ``Conda Env`` from the dropdown menu.

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.

Creating a New Anaconda Environment
-----------------------------------

Wing Pro can also create a new Anaconda environment with ``conda create`` at the same time that it
creates a new project.  To do this, select ``New Project`` from the ``Project`` menu, choose
the source directory to use with your project, and press the ``Next`` button.  Then select
``Create New Environment`` and choose ``Conda Env`` from the menu of available environment types.

You will need to enter the name for the new environment, choose the location to write the
new environment, select the installation directory of the Anaconda that you want to use,
and specify at least one package to install into the new environment.

Package specifications may either be entered directly into the ``New Project`` dialog, in
a space-separate list, or read from an existing ``requirements.txt`` or ``Pipfile``. In
both cases, the package specifications may be anything accepted by ``conda install``
including just the package name, ``package==version``, or ``package>=version``::

  flask
  gunicorn
  numpy==1.17.4  
  django>=3.1

When the ``New Project`` dialog is submitted, it will run ``conda create`` and then
configure the project to use the new environment.

Package Management
------------------

Once you've configured your project to use an Anaconda environment, you can use the
``Packages`` tool in the ``Tools`` menu to list, add, remove, or update packages. See
`Package Manager <ref:packages/intro>`__ for details.

About Anaconda Environments
---------------------------

On Windows, Anaconda may fail to load DLLs when its ``python.exe`` is run directly without
using a named environment. 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::

  builtins.ImportError:
  IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
  Importing the numpy c-extensions failed.
  ...
  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 are affected by it.

The solution to this problem is to set the ``Python Executable`` in Wing's ``Project Properties`` to
``Activated Env`` and enter the full path to the ``Scripts\activate.bat`` in your Anaconda
installation. To find out where Anaconda is installed, start it up outside of Wing and look at the
value of ``sys.executable`` after ``import sys``.

This problem may also occur when running Anaconda Python outside of Wing without using a named
Anaconda environment or when using virtualenv with Anaconda. To fix this, you can call ``conda
activate base`` before starting Anaconda or activating your virtualenv.

Note that in some cases this problem will not occur in Wing even though it appears on the command
line outside of Wing.  This is because Wing tries to detect when Anaconda is being used and then,
if needed, automatically activates the base environment before launching Anaconda.

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.

