Skip to content
Tyler Wolfe-Adam edited this page Oct 29, 2020 · 1 revision

How the Java-Python connection works

Traditionally, Python code is executed by either running pre-written files or interpretively (executing the code directly) – and it’s the latter method that Pypeline takes advantage of. One way to run Python interpretively is by opening a command prompt, navigating to the Python installation directory, and running the Python executable (as seen in the screenshot below).

Command prompt - interactive Python 1

Note: The cd command is used to change the active directory; Irrelevant text is blurred

To avoid having to constantly navigate to the directory an executable file is in, all systems have a system “path”. The path consists of a series of folders that tell your system where to look for executables. If you have the Python installation directory on your system path, you can start the Python executable from anywhere (as seen in the screenshot below).

Command prompt - interactive Python 2

This lays the foundation for how Pypeline is able to interact with a live Python environment. Behind the scenes, it runs a command to search for a version of Python on your system path. For Windows, it uses the where command and for Mac/Linux it uses the find command. What it searches for depends on the configuration you setup in the Pypeline Communicator object inside AnyLogic.

Command prompt - interactive Python 3

If multiple executables are found on the system path, only the top-most one is used; you can resolve this by changing your system path or in the Pypeline Communicator’s preferences With the interpretive environment created, the code is run (via the provided functions, as part of the Pypeline Communicator object) just like any other interpretive environment.