Configure Python for ExternalEvaluate

Configure your system to evaluate external Python code.

Prerequisites

Python must first be installed on your system. Installers for all systems are available from (WebLink[https://www.python.org, https://www.python.org]).

Python 2.7 comes pre-installed on Mac.

The Python package manager, pip, is necessary to install the zmq sockets package for communication with the Python evaluator. Refer to Python documentation on how to install pip if it is not available on your system.

All versions of Python 2.7+ and 3.4+ are supported.

Install zmq

Once Python and pip have been installed, the zmq package can be installed.

$ pip install zmq

On Windows, this is the command to install zmq.

> pip.exe install zmq

Verify the Installation

Once the installation is successful, (RefLink[FindExternalEvaluators, paclet:ref/FindExternalEvaluators]) should discover the installation automatically.

FindExternalEvaluators["Python"]

Possible Issues

If you have installed Python according to the steps above, but it is not discovered by (RefLink[FindExternalEvaluators, paclet:ref/FindExternalEvaluators]), you can register it manually—with (RefLink[RegisterExternalEvaluator, paclet:ref/RegisterExternalEvaluator]), for example.

RegisterExternalEvaluator["Python","/usr/local/bin/python3"]

Note that multiple evaluators may appear for each different form of the Python executable that all use the same installation of Python. In the following setup, both the executables "/usr/local/bin/python3" and "/usr/local/bin/python3.6" point to the same installation.

FindExternalEvaluators["Python"][Select[#Version==="3.6.1"&],Append[KeyDrop["Registered"]@#,"InstallLocation"->ExternalEvaluate[{"Python","Executable"->#Executable},"import sys; sys.executable"]]&]