1

Dymola-Python Interface. No module named Dymola

I have been working trying to run Dymola through python. The goal is to give in values and read results without opening Dymola. The constant error that i am getting is "There is no module named Dymola" Please help!! I couldn't find much help online. Thank you in advance!

rb8685's avatar
11
rb8685
asked 2023-01-23 12:31:58 -0500
Aaron Boranian's avatar
14.1k
Aaron Boranian
updated 2023-01-24 09:04:03 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

0

Without your test script or more info, it's hard to tell whether you have incorrectly configured the path to the Dymola python module or whether it's another issue (like casing, the module is apparently dymola, not Dymola)

(It also doesn't help that I don't use windows neither do I use Dymola... :))

Seems like it should probably start with from dymola.dymola_interface import DymolaInterface, and if you aren't setting your PYTHONPATH variable before launching python (set PYTHONPATH=%PYTHONPATH%;C:\Path\to\Dymola\Modelica\Library\python_interface\dymola.egg), you should have something like his before trying to use dymola:

import sys
from pathlib import Path
DYMOLA_INSTALL_PATH = Path(r'C:\path\to\Dymola\')
DYMOLA_EGG = DYMOLA_INSTALL_PATH / 'Modelica/Library/python_interface/dymola.egg'
sys.path.insert(0, str(DYMOLA_EGG))

from dymola.dymola_interface import DymolaInterface
dymola = DymolaInterface()
res = dymola.simulate("myModel")

Personal 2 cents: I generally recommend using the sys.path.insert inside the script approach instead of setting the PYTHONPATH env variable, you'll avoid some issues.

Julien Marrec's avatar
29.7k
Julien Marrec
answered 2023-01-27 02:27:11 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments