Launching PyMechanical#
PyMechanical requires either a local or remote instance of Mechanical to communicate with. This page describes how to launch Mechanical in each mode.
Tip
If you are not sure which mode to use, see Choose your mode.
Remote session mode#
In remote session mode, Mechanical runs as a separate server process and uses gRPC to communicate with Python.
Launch from Python#
Use the launch_mechanical() method to launch and connect automatically:
>>> from ansys.mechanical.core import launch_mechanical
>>> mechanical = launch_mechanical()
>>> mechanical
Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:261
Software build date: 02/03/2026 15:29:09
To select a specific version:
exec_file_path = "C:/Program Files/ANSYS Inc/v261/aisol/bin/win64/AnsysWBU.exe"
mechanical = launch_mechanical(exec_file=exec_file_path)
Launch from the command line#
Start Mechanical in server mode and connect manually:
$ ansys-mechanical --port 10000
For all CLI options, run ansys-mechanical --help or see ansys-mechanical.
Connect to a running instance#
Connect to a local or remote Mechanical server:
from ansys.mechanical.core import Mechanical
# Local — default IP (127.0.0.1) and port (10000)
mechanical = Mechanical()
# Remote — by IP address
mechanical = Mechanical("192.168.0.1", port=10000)
# Remote — by hostname
mechanical = Mechanical("myremotemachine", port=10000)
Alternatively, use the connect_to_mechanical() method:
from ansys.mechanical.core import connect_to_mechanical
mechanical = connect_to_mechanical("192.168.0.1", port=10000)
For more on remote sessions, see the Remote session user guide.
Embedding mode#
In embedding mode, Mechanical uses Python.NET. to run directly inside your Python process. This gives you full object-model access with no network overhead.
Launch on Windows#
>>> from ansys.mechanical.core import App
>>> app = App()
>>> app
Ansys Mechanical [Ansys Mechanical Enterprise]
Product Version:261
Software build date: 02/03/2026 15:29:09
Launch on Linux#
On Linux, certain environment variables must be set before Python starts.
Use the mechanical-env script shipped with PyMechanical:
$ mechanical-env python
Then use the same Python code as on Windows.
For more on embedding, see the Embedding mode user guide.
See also
Troubleshooting — executable not found, licensing, VPN, and debug tips.