Using Wing with Anaconda

Classic+

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

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 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 choose Anaconda's python.exe or python. In many cases, Wing will automatically find Anaconda and include it in the drop down shown for this option. Otherwise, choose Other: there and enter its full path. 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:

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.

If you are creating a new Wing project and want to use Anaconda, select New Project from the Project menu and set Environment under Python to Existing Python. Then select Anaconda from the Python Executable drop down, or choose Other: and enter its full path as described above. To use an existing Anaconda environment as an Activated Env, set Environment to Existing Env instead and select the environment in Activate, which lists the environments in each Anaconda installation found. Note that you can create a new Anaconda environment from the New Project dialog, as described below.

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 (the ⋯ button).

Creating a New Anaconda Environment

Wing 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 and choose the source directory to use with your project with the New directory, Existing directory, or Clone repository card. Then, under Python, set Environment to New Env and Manager to Conda Env.

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

Alternatively, set Package File to an existing Anaconda environment.yml to create the environment from it.

When the New Project dialog is submitted, it will run conda create and then set the project's Python Executable to Activated Env with the command that activates the new environment.

Using micromamba and pixi Environments

Environments created by micromamba or pixi can be used in the same way, by setting Environment to Existing Env in the New Project dialog and entering the environment's directory under Other:. Wing runs a pixi environment with pixi run --frozen, so a launch never changes your pixi.lock, and a micromamba environment with micromamba run. When a pixi project's directory is selected with the Existing directory card, Wing finds and selects its default environment.

On Windows, micromamba run changes arguments that contain % or &, so Wing activates a micromamba environment with the activate of an installed Anaconda instead. If you have none, install Miniconda to activate the environment. See How Projects Run Each Kind of Environment in Creating Python Environments for details.

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 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 automatically activates the environment that the Python belongs to, either the base environment or one created with conda create, even when Command Line is used.

Related Documents

For more information see: