Skip to content

ansys/pymechanical

PyMechanical logo

PyAnsys PyPI Python GH-CI Codecov MIT Ruff pre-commit Ask DeepWiki

Overview

PyMechanical is a Python interface for Ansys Mechanical, enabling automation and integration of complex simulation analysis workflows. It supports both remote sessions and embedded instances.

Compatibility

Supported versions:

  • Python: 3.10 - 3.13
  • Mechanical: 2024 R1 (v241) to 2025 R2 (v252)
  • Platforms: Windows, Linux

Installation

Install from PyPI:

pip install ansys-mechanical-core

For graphics support:

pip install ansys-mechanical-core[graphics]

For RPC functionality:

pip install ansys-mechanical-core[rpc]

Requirements:

  • Licensed copy of Ansys Mechanical (2024 R1+ on Windows/Linux).
  • For embedded instances: Local Mechanical installation required.
  • For remote sessions: Network access to a running Mechanical instance.
  • Python 3.10 - 3.13

Quick start

Remote session:

import ansys.mechanical.core as pymechanical

# Launch a new Mechanical instance
mechanical = pymechanical.launch_mechanical()
result = mechanical.run_python_script("2+3")
print(result)  # Output: 5
mechanical.exit()

Connect to existing instance:

import ansys.mechanical.core as pymechanical

# Connect to a running instance on port 10000
mechanical = pymechanical.connect_to_mechanical(port=10000)
result = mechanical.run_python_script("Model.Name")
print(result)

Embedded instance:

import ansys.mechanical.core as pymechanical

# Create an embedded Mechanical app
app = pymechanical.App()
app.update_globals(globals())

# Access Mechanical objects directly
print(DataModel.Project.ProjectDirectory)

# Add analysis and solve
model = Model
static = model.AddStaticStructuralAnalysis()
static.Solution.Solve(True)

Troubleshooting

Common issues:

  • Connection refused: Ensure Mechanical is running and the port is accessible.
  • License error: Verify your Ansys license is properly configured.
  • Import error: Check that ansys-pythonnet is installed (not pythonnet).
  • Linux embedding: Use mechanical-env to run python scripts for embedded mode.

Documentation and support

About

Pythonic interface to Ansys Mechanical ™

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 24