Simcenter Amesim How to use Amesim API modules in Spyder IDE

Simcenter Amesim Automation Connect Simcenter System Simulation Client for Git Simcenter Amesim Teamcenter Share


This article explains how to use the Amesim API modules in Spyder IDE. It covers setting up a Python 3.8 environment with Anaconda, tweaking Spyder settings to match a specific Amesim version, and some steps to ensure Amesim APIs work with this setup. Follow along to get Amesim and Spyder working together without any hitches.



Spyder is a popular IDE tailored for Python. It offers a user-friendly workspace with a rich set of tools, like an interactive console, advanced debugging capabilities, and an intuitive editor. Integrating Simcenter Amesim with Spyder can streamline beginners and advanced user's workflow. Instead of switching between platforms, they can use the power of Amesim modules directly within the Spyder environment, making their simulation and modeling automatization tasks smoother and more efficient.

Step 1: Create a dedicated environment based on a Python 3.8 version (minor index doesn’t matter)

By creating a specific environment for Amesim, you isolate the setup and ensure that any packages you install don't interfere with other projects. The ame_apy module's dependency on Python 3.8 highlights the importance of version-specific environments. This way, when you're using Amesim's tools, you're confident they'll run smoothly without version conflicts.

This is important, because the ame_apy module is a C-extension that requires to be loaded by a Python 3.8 version. This environment will allow us to install our needed modules, in order to avoid to install them directly in the Amesim installation folder.

Step 2: Install the spyder-kernels package required by Spyder to support the console.

Spyder relies on the spyder-kernels package. This package allows Spyder's console to execute Python code, display outputs, and offer debugging capabilities. Without it, the interactive nature of Spyder is compromised.

Additional modules that our scripts require need to be added from here as well (or using the prompt of the new Amesim environment).

Step 3: Select the python interpreter associated with the new environment created in Anaconda.

When using Spyder, it can tap into any Python environment you have on your machine. By specifically pointing Spyder to the environment you set up for Amesim, you ensure that any Amesim-related code you run will have access to the necessary libraries and the correct Python version. This setting ensures consistency and reduces the chance of runtime errors.

Install Spyder in the new Amesim environment and adjust its preferences settings to use the interpreter associated to it.

(Type conda info in the new Amesim environment prompt if you can’t find the location directly)

Step 4: Configure Python to Access and Load Amesim's ame_py Module and Dependencies

Now we need to make Python be able to find and load the Amesim ame_py module and dlls. In order to locate the them we add them to the PYTHONPATH environment variable.


However, this is not enough. The ame_apy depends on Amesim binaries DLLs that need to be found. Normally, these are found in the PATH environment variable, but starting from the Python 3.8, those DLLs search path need no be explicitly added using the add_dll_directory from the os module.

import os
# Add Amesim DLLs directory
os.add_dll_directory(os.path.join(os.getenv("AME"), "win64"))
import ame_apy

This step is automatically done when using the Python interpreter from the Amesim installation, but here we have to do it because we are using another interpreter. The trick consists in adding a .pth file in the Anaconda environment site_packages directory that will be loaded and executing at start time, in order to:

  • Add Amesim python module search paths (no need to customize the PYTHONPATH).
  • Add Amesim binaries search paths.

You can use the following line to populate the amesim_hook.pth file (use the correct Amesim installation path):

import os;
os.add_dll_directory(r"C:\Program Files\Simcenter\2210\Amesim\win64")
os.add_dll_directory(r"C:\Program Files\Simcenter\2210\Amesim\scripting\python")
os.add_dll_directory(r"C:\Program Files\Simcenter\2210\Amesim\scripting\python\win64")

Note: We probably need to call above lines in the script when we open Spyder for the first time, after this is called, the dlls are handled by the .pth file.

Normally, this should allow us to use Amesim modules in Spyder IDE.


KB Article ID# KB000122254_EN_US



Associated Components

Amesim Automation Connect