************************************
How to set up an IDE to use Anaconda
************************************

.. contents:: The following integrated development environments (IDEs) can be used to run Anaconda:
   :local:

Spyder
------

`Spyder <http://spyder-ide.org>`_, the Scientific PYthon Development EnviRonment, 
is a free interactive development environment (IDE) that is included with Anaconda. It 
includes editing, interactive testing, debugging and introspection features.

After you have installed Anaconda, you can start Spyder on macOS, Linux, or Windows 
by opening a Terminal or Command Prompt window and running the command ``spyder``.

Spyder is also pre-installed in the graphical :doc:`navigator` included in Anaconda. 
In the Navigator "Home" tab, just click the Spyder icon.

Python for Visual Studio Code
-----------------------------

`Visual Studio Code <https://code.visualstudio.com/>`_ (VSC) is a free cross-platform source code
editor. The `Python for Visual Studio Code <http://donjayamanne.github.io/pythonVSCode/>`_
`extension <http://marketplace.visualstudio.com/items?itemName=donjayamanne.python>`_
allows VSC to connect to Python distributions installed on your computer.

If you've installed Anaconda as your default Python installation and installed Python for Visual Studio Code,
your Visual Studio Code installation is already set to use Anaconda's Python interpreter.

* To create a new Python source code file select *File -> Open ...* to choose a directory to place the code. Then select *File -> New File* to create a new file.

.. image:: img/anaconda_VSC_newfile.png
   :height: 300px

* To associate the new file with the Python interpreter, click the *Plain Text* button at the bottom of the window.

.. image:: img/anaconda_VSC_plaintext.png

* From the pull-down menu type or select Python, add source code and save the file from *File -> Save*.

.. image:: img/anaconda_VSC_python.png
   :height: 300px

* Open the Debug pane by clicking the bug icon and click the gear configuration button. From the pull-down menu select Python.

.. image:: img/anaconda_VSC_debug1.png
   :height: 300px

* Select the Python source tab and click the green run arrow. The source code will be run using your Anaconda Python interpreter.

.. image:: img/anaconda_VSC_debug2.png
   :height: 300px

Python Tools for Visual Studio (PTVS)
-------------------------------------

`Python Tools for Visual Studio <http://microsoft.github.io/PTVS/>`_ is a free, open source plugin 
that turns Visual Studio into a Python IDE.

If you've installed Anaconda as your default Python installation and installed PTVS, your 
Visual Studio installation is already set to use Anaconda's Python interpreter in PTVS.

You can verify this by creating a new Python project and checking whether Anaconda 
is the Python it uses.

* To create a new Python project, navigate to *File -> New -> Project* (keyboard shortcut: CTRL+SHIFT+N) and select ``Python Application``.

.. image:: img/PTVS_newproj.png
   :height: 300px

* To check which Python the project uses, navigate to *Tools -> Python Tools -> Python Interactive* (keyboard shortcut: ALT+I).

.. image:: img/PTVS_pythoninteractive1.png
   :height: 300px

1. In the Python Interactive window, type ``import sys``, then press Enter.
2. Type ``sys.version``, then press Enter.

If PTVS is using Anaconda, you will see your Anaconda Python version displayed. In the example below it is Anaconda 1.5.0 (64-bit).

.. image:: img/PTVS_pythoninteractive2.png
   :height: 150px

If PTVS does not automatically discover Anaconda, see the `official PTVS 
documentation <https://github.com/Microsoft/PTVS/wiki>`_, especially the 
section on `Selecting and Installing Python Interpreters 
<https://github.com/Microsoft/PTVS/wiki/Selecting-and-Installing-Python-Interpreters>`_ 
and the `PTVS installation instructions 
<https://github.com/Microsoft/PTVS/wiki/PTVS-Installation>`_.


PyCharm
-------

`PyCharm <http://www.jetbrains.com/pycharm/>`_ is an intelligent Python IDE for Windows, macOS 
and Linux, that is offered in a Community version for free and a Professional version for a fee.

Use PyCharm's *Preferences* to set it to use Anaconda. There are multiple 
methods to access the Preferences Window, including selecting Preferences 
within the PyCharm file menu or by clicking the Preferences icon in the top 
icon bar.

.. image:: img/PyCharm_iconbar.png
   :height: 35px

.. image:: img/PyCharm_menu.png
   :height: 200px

After the Preferences window is open, navigate to *Project Interpreter -> Python Interpreters*.  
Click on the + sign to add Anaconda to the Python Interpreters list.

.. image:: img/PyCharm_preferences1.png
   :height: 300px

If the Anaconda Python path is not listed, select *Local...* and navigate to :ref:`the 
Anaconda Python interpreter path <python-path>`.

After you have added Anaconda, you will see it displayed in the list of Python Interpreters, along with the other packages that were installed with it.  Click *OK*. The PyCharm IDE is 
now set up to use Anaconda.

.. image:: img/PyCharm_preferences2.png
   :height: 300px

MORE INFO: `Official PyCharm documentation <http://www.jetbrains.com/pycharm/help/pycharm.html>`_, 
and the `Configuring Available Python Interpreters section <https://www.jetbrains.com/pycharm/help/configuring-available-python-interpreters.html>`_.


Eclipse and PyDev
-----------------

`Eclipse <http://www.eclipse.org/downloads/>`_ is an open-source platform that provides an array of convenient
and powerful code editing and debugging tools. `PyDev <http://pydev.org/>`_ is a Python IDE that runs on top of Eclipse. 

If you do not already have Eclipse and PyDev installed:

* `Download Eclipse <http://www.eclipse.org/downloads/>`_ and read the `Eclipse resources <http://www.eclipse.org/resources/>`_.
* You may need to install the latest `Java JDK/JRE <http://www.oracle.com/technetwork/java/javase/downloads/index.html>`_ 
  before installing PyDev in order for PyDev to show up in the Eclipse Preferences menu after PyDev installation.
* `Install PyDev <http://pydev.org/manual_101_install.html>`_.

After you have Eclipse, PyDev, and Anaconda installed, follow these steps to set Anaconda Python as your 
default by adding it as a new interpreter, and then selecting that new interpreter:


1. Open the Eclipse *Preferences* window:

.. image:: img/Eclipse1.png
   :height: 200px

2. Go to *PyDev -> Interpreters -> Python Interpreter*.
3. Click the New button:

.. image:: img/Eclipse2.png
   :height: 300px   

4. In the "Interpreter Name" box, type "Anaconda Python".
5. Browse to :ref:`the Anaconda Python interpreter path <python-path>`.
6. Click the OK button.

.. image:: img/Eclipse3.png
   :height: 150px

7. In the next window, select all the folders and click the OK button again to 
select the folders to add to the SYSTEM python path.

.. image:: img/Eclipse4.png
   :height: 300px   

8. The Python Interpreters window will now display Anaconda Python. Click *OK*. 

.. image:: img/Eclipse5.png
   :height: 300px   

You are now ready to use Anaconda Python with your Eclipse and PyDev
installation.


Wing IDE
--------

`Wing IDE <http://www.wingware.com/>`_ is an IDE designed specifically for the Python 
programming language. Wing IDE is offered in Professional, Personal, and Free 101 versions.

To set up your Wing IDE installation to use Anaconda:

1. Navigate to the Python configuration window. In Wing 101 this is *Menu -> Edit -> Configure Python*, 
   and in Wing Personal and Wing Professional this is *Menu -> Project -> Project Properties*.
   The Wing 101 menu looks like this:

.. image:: img/WingIDE1.png
   :height: 250px

2. Select the *Custom* option for Python Executable.

3. Click *Browse...* and navigate to :ref:`the Anaconda Python interpreter path <python-path>`.

4. Select the Custom option for Python Path.

5. Click *Insert* and browse to :ref:`the Anaconda Python interpreter path <python-path>`.

6. Select *OK*.

.. image:: img/WingIDE2.png
   :height: 200px

7. If you are prompted to reload your Python shell, do so. After the reload, you will
   see Anaconda in the Python Shell tab.

Wing IDE can use Anaconda's Python now.

.. image:: img/WingIDE3.png
   :height: 200px   

For more information, check out
the `official Wing IDE documentation <http://www.wingware.com/support>`_.


Ninja IDE
---------

`Ninja IDE <http://ninja-ide.org/>`_ is a cross-platform free and open source IDE 
specially designed for Python application development.

To use Anaconda Python with the Ninja IDE:

1. Go to *Project -> Open Project Properties*

.. image:: img/NinjaIDE_1.png
   :height: 150px   

2. In the *Project Execution* tab, select Anaconda Python for the Python Custom Interpreter. Enter :ref:`the Anaconda Python interpreter path <python-path>`.

.. image:: img/NinjaIDE_2.png
   :height: 350px   

3. Verify that this works by creating a test script. Enter this code:

.. code-block:: python

  import sys
  print(sys.version)

4. Run your test script. In the output screen, you will see your Anaconda Python version listed.

.. image:: img/NinjaIDE_3.png
   :height: 350px   

For more information, check out
the `Ninja-IDE documentation <https://ninja-ide.readthedocs.org/en/latest/>`_.


IDLE
----

IDLE is a very small and simple free cross-platform IDE that is included with 
Python and is released under the open source Python Software Foundation License.

Anaconda and Miniconda include IDLE. Find the IDLE program file in a file 
explorer and run it, or run it from the command line by typing the full path 
and pressing return.

For example, if you install Miniconda with Python 3 on macOS and your username 
is "jsmith", the full path may be ``/Users/jsmith/miniconda3/bin/idle3.5``. On 
Widows, the full path may be ``C:\Users\jsmith\Miniconda3\Scripts\idle``.

You can also use your operating system to make a shortcut to this file as an 
icon on the desktop or an item on the main operating system menu.

.. _python-path:

Finding your Anaconda Python interpreter path
---------------------------------------------

IDEs often require you to specify the path to your Python interpreter. This path
can be in many places depending on which operating system version and which
Anaconda version you use. This guide will help you search your file system to
find your Anaconda Python interpreter path.

The Python interpreter in Anaconda is usually installed in your home directory
in a folder such as ``anaconda/bin/python``.

On Windows this might be a path such as ``C:\Users\Jane Smith\anaconda\bin\python``.

On macOS this might be a path such as ``~/anaconda/bin/python`` or
``/Users/jsmith/anaconda/bin/python``.

On Linux this might be a path such as ``~/anaconda/bin/python`` or
``/home/jsmith/anaconda/bin/python``.

As well as ``anaconda``, the folder in your home directory might be named
``anaconda2`` or ``anaconda3``.

If you have installed Miniconda instead of Anaconda, the folder might be named
``miniconda``, ``miniconda2``, or ``miniconda3``.
