Skip to content
Tyler edited this page Apr 20, 2024 · 3 revisions

Troubleshooting

As Pypeline relies on the existence of Python in your system path, and with each system being different, you may encounter different issues when trying to setup or during use. This page aims to help with troubleshooting by describing potential problems, explaining why they occur, and solutions.


Unable to add the library

Problem:

When trying to add the library, you receive a message about how "the model was created by a newer version of AnyLogic".

Example:

324171160-9b1ea26d-9529-495b-90f3-7f0d8d77c874

Explanation:

The error message refers to the library as a model because all libraries you add to your palette (such as Pypeline) are technically AnyLogic models! And as AnyLogic models are not forwards compatible, trying to open a model created in a version after the one you have installed will not work.

Additionally, disregard the "ALP version" number - this is referring to an internal versioning number that is typically a few versions behind your current one. In the example above, ALP version 8.8.3 was used by later versions of 8.8.6. An unmaintained lookup table can be found in this gist.

Solution:

The official solution (recommended) is to upgrade your AnyLogic version to the latest version or to contact the support team if you want a specific version.

The unofficial solution is to recompile the library for your own version. However to do this requires manually modifying the source ALP file in a text editor, so do this at your own risk (there is little, but it needs to be said). Here are the steps:

  1. Download this repo to your local directory (e.g., Code tab > green 'Code' button > Download zip > extract)

  2. In a text editor, open the file 'AnyLogic-Pypeline/Source/AL-Pypeline Library/Pypeline Library.alp". Keep it open while you do the next steps.

  3. Find (or create) a model created in your current AnyLogic version. Open its "alp" file in any text editor.

    Hint: From inside AnyLogic, you can see where a model is saved by clicking on its name in the Projects panel, then checking the Properties panel

  4. Within the first few lines, you should see one starting with <AnyLogicWorkspace, copy that entire line.

  5. In the Pypeline alp file from the earlier step, replace its <AnyLogicWorkspace line with the copied one.

  6. Save and close the text files.

  7. Open AnyLogic and then the model "Pypeline Library.alp"

  8. Click the build-icon build button, fix any errors (there typically should be none).

  9. Export the library, saving the jar to a location where it won't be removed or deleted. For more on this step, see the help article Library Editor > Exporting.


Executable path error

Problem:

After running your AnyLogic model, you receive an error during model startup with a message about the path to the Python executable (an example can be seen in the first image below). Clicking on the Communicator object shows "null" or "Info n/a" (seen in the second image below).

Error message

Communicator inspection with error

Explanation:

No version of Python could be found based on how the Communicator's properties were configured. You will see this error if, under the Communicator's properties, for the command to call Python, you have chosen "python", "python2", "python3", or "(other)". The error signifies that it tried calling the relevant command, but no version of Python responded. This is most likely due to not having an executable that sits on your system path.

Solution:

You have two options:

  1. Add the Python executable to your desired version of Python to the system path. To do this, first find the Python install directory (where the executable lives). Then, depending on your OS, follow any tutorial for modifying the system path. For convenience, here are three for each major OS (not affiliated with the Pypeline project or The AnyLogic Company):

  2. Use the "(path)" option and paste in the path to the Python executable


No executable found error

Problem:

After running your AnyLogic model, you receive an error during model startup with a message about no Python executable being located at the specified path (an example can be seen in the first image below). Clicking on the Communicator object shows "null" or "Info n/a" (seen in the second image below).

Error message

Communicator inspection with error

Explanation:

No version of Python could be found based on how the Communicator's properties were configured. You will see this error if, under the Communicator's properties, for the command to call Python, you have chosen "(path)". This happens when the path that's been specified does not have a Python executable within it (if the path is a directory) or the file does not exist (if the path is to the executable).

Solution:

For the custom path specified in the Communicator's properties, ensure that it is correct and points to a valid Python executable.


IOException error

Problem:

After running your AnyLogic model, you receive an "IOException" with a message about Python not being found. Clicking on the Communicator object shows "null" and a path to Python under a "WindowsApps" directory.

Communicator inspection and error

Explanation:

This is similar to the first problem, in that it's an issue with your system path/Communicator configurations, but is specific to Windows. In later versions of Windows 10, Microsoft included a version of Python inside the Windows store. If you go to a command prompt and try to enter in the python command, it will open the Windows store to where you can download it. It is not recommended to download from here. Rather, you should install from python.org or use other Python environments, such as Spyder, Anaconda, et cetera.

Solution:

Please see the solution to the first problem. Additionally, if you do not want to have the python or python3 commands link to the Windows version, do the following:

  1. Open the start menu and navigate to Windows Settings by clicking on the gear icon (above the power, in the lower left).

  2. Navigate to Apps > App execution aliases

  3. Disable the "App Installer" options for "python.exe" and "python3.exe"


Invalid escape sequence build error

Problem:

When trying to run your AnyLogic model, you receive the error "Invalid escape sequence".

Problems panel

Explanation:

In Java, the backslash () is a special character that is used to "escape" other characters in order to represent certain non-alphanumeric characters. One example of this is if you want a string that has a double quote character in it. For example:String name = "John "The man" Doe";This also applies to whitespace characters, such a tab (\t) or new line (\n). For example, running the code shown in the first image below produces the text shown in the second image below:

Example of backslash in code

Example of backslash in execution

What this error message is referring to is that a single backslash was used within a string with an invalid character following it. If you have a string that starts with "C:\Program Files", it throws the error because it doesn't recognize the character "\P". In this case, it's trying to interpret what is meant as a literal-P as if it were one of the "special" characters.

Solution:

Most likely, you are on a Windows machine and have the command to call Python set to "(path)" with a custom path specified. Simply add an extra backslash to each backslash.

Incorrect path

Corrected path


Generic error troubleshooting

Problem:

While running your model (at any point), you receive an exception or error with some other type of exception or error mentioned.

Various types of error messages

Explanation:

This error appears because the option for "Throw error on failed Attempt" in the Communicator's properties is enabled (shown in the image below) and one of the commands to Python had failed.

Throw error option in Properties

As these types of messages popup whenever any exception or error happens in AnyLogic (i.e., not related to Pypeline), it's good to know how to interpret these. Using the last example error shown above, take a look at the different parts of it. The image has been copied below and annotated, with the callouts referenced by the list below it:

Breakdown of error message

  1. This is a message from AnyLogic telling you the type of moment that the exception or error occurred at.

  2. This is another message from AnyLogic telling you where the problem originated from. Specifically, it consists of the agent – in this case root, which refers to your top-level agent (typically Main) – and the name of the object – in this case pyCommunicator. You may also see the specific type of exception listed before this (as seen in the first example image above).

  3. This is a message that provides more details about the exception or error regarding what went wrong. For Pypeline, this is the message received from Python as the feedback of a command being executed that fails. In other words, if the isSuccessful() command returns false, then then this text will be the output of the getFeedback() function.

  4. This is a reference to the AnyLogic console; for this example, the console is shown in the image below:

Console error

While it can be daunting to try to understand what is going on, there is some useful information here to figure out where in the model that this error occurred. This block of red text is called a "stack trace" and describes the events leading up to the exception or error. Most of the lines are related to the AnyLogic engine, but one line that stands out is related to the onStartup function of the Main agent. This confirms annotation 1 shown above, which states the problem happened when the model started up. If you were to take a look at the "On startup" field of Main, you would see the problematic code shown in the following image:

On startup code

As the message from Python – ModuleNotFoundError("No module named 'fake\_library'",) – states, this command failed because the library fake_library was not found.

Solution:

As this problem originates from your Python code, there is no one solution. However, if you do not want the entire model to come to a halt if an error occurs in Python and you instead want to handle it from AnyLogic, simply uncheck the option for "Throw error on failed attempt".

One use-case for this is if you want to have fallback logic. An example is shown in the images below. If the parameter favoriteNumber is set to zero, the first run function call will return a ZeroDivisionError in Python. In other words, the Communicator is telling Python to run the code: reciprocal = 1 / 0 – code which will return the aforementioned error when executed. Instead of halting the entire AnyLogic model when this happens, it is handled by additional code that executes after the attempt to the run function call.

Specifically, it first checks to see whether the attempt was successful. If not, it then lets the user know this happened and then sets the variable to a fallback value (0).

Error handling example

If this is still unclear, create a new AnyLogic model and play around with it yourself. Additionally, the demo model called "Demo – Basic Functions" shows an example of this.


(Mac OS) Python selection problems

Problem:

(Mac OS users) You have ensured a specific version of Python is on your PATH, and that you can use the python (or other) command to run it. However, it cannot find the specified version or falls back to the built-in Python 2.

Mac inspection window and terminal

Explanation:

Unlike when using Windows, Mac OS has different environments for different processes (in this case, between a Java GUI application – AnyLogic - and the shell). When AnyLogic is launched, it uses the default environment, which only contains a few system-only-accessible directories. If you print the value of your system path from the terminal versus AnyLogic, you can see the difference. As you can see between the two screenshots below, the value of the system path that is accessible from within AnyLogic only contains system-accessible directories.

Terminal output

Path printing from AnyLogic

Solution:

There are two ways to solve this. TODO GET INFO FROM SUPPORT EMAIL.


If you have further problems, please file them in the "Issues" tab on the Pypeline GitHub repository.

Filing GitHub issue