Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question

Python-Dymola Interacting Issues

asked 2016-01-26 22:02:41 -0500

world2005 gravatar image


I am using Modelica Building Library from Berkeley lab. I am interested in using Python-Dymola interacting function, and I can successfully run the example: Buildings.Utilities.IO.Python27.Functions.Examples.Exchange.

However, when I try to import modules, numpy, sklearn, or tensorflow, in, Dymola responses errors:

Failed to load "testFunctions". This may occur if you did not set the PYTHONPATH environment variable or if the Python module contains a syntax error.

The error message is "ImportError('Traceback (most recent call last):\n File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/", line 37, in <module>\n from tensorflow.core.framework.graph_pb2 import *\n File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/", line 8, in <module>\n from google.protobuf import reflection as _reflection\n File "/usr/local/lib/python2.7/dist-packages/google/protobuf/", line 58, in <module>\n from google.protobuf.internal import python_message as message_impl\n File "/usr/local/lib/python2.7/dist-packages/google/protobuf/internal/", line 53, in <module>\n from io import BytesIO\n File "/home/cchang11/anaconda2/lib/python2.7/", line 51, in <module>\n import _io\nImportError: /home/cchang11/anaconda2/lib/python2.7/ The stack of functions is:"test", "qq", {2}, {0}, {""}, 1, 1, 0, 0, 0) Error: Failed to start model.

I tried to insert the following path but it still dose not work.

import sys

sys.path.insert(0, '/home/cchang11/anaconda2/lib/python2.7/site-packages')

import sklearn

Do I have to generate a new dynamic linked library like Could anyone let know how to generate a new library for Dymola?

Thank you very much.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-01-27 17:24:28 -0500

Did you set the PYTHONPATH as described in before you started Dymola?

The following import works for me:

def r1_r1(xR):
  import buildingspy.development.refactor as bp
  return 2.*xR

Note however that Dymola generates by default 32 bit, but your Python installation may contained compiled C code that is 64 bit.

You should not have to recompile as long as you use 32 bit.

edit flag offensive delete link more


Yes, I did. For 32bit case, I can correctly run the example. However, if I add "import numpy", dymola shows error. In the meanwhile, I use the 64bit library inside buildingspy package with from my system python folder, and set dymola compiler to 64bit. When I run the buildingspy example again, dymola shows segment fault. Is there a way to make buildingspy use 64bit machine or to let me import extra python package such as numpy or sklearn? Thank you!

world2005 gravatar imageworld2005 ( 2016-01-27 17:58:02 -0500 )edit

@world2005: do you also get a segmentation fault on 64 bit if you do not import anything, i.e., simply run Buildings.Utilities.IO.Python27.Functions.Examples.Exchange?

I made some updates to the Python code but still get a segmentation fault on 64bit Linux Ubuntu, see

Michael Wetter gravatar imageMichael Wetter ( 2016-02-02 20:54:30 -0500 )edit

@Michael Wetter: Yes, I also got a segmentation fault on 64bit without importing any module, and I have no idea where is going wrong.

world2005 gravatar imageworld2005 ( 2016-02-03 00:26:50 -0500 )edit
Michael Wetter gravatar imageMichael Wetter ( 2016-02-05 11:09:21 -0500 )edit

@Michael Wetter: thank you very much! I very much appreciate your help!

world2005 gravatar imageworld2005 ( 2016-02-06 19:18:52 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer


Question Tools

1 follower


Asked: 2016-01-26 22:02:41 -0500

Seen: 304 times

Last updated: Jan 27 '16