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

Python-Dymola Interacting Issues

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

world2005 gravatar image

Hi,

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 testFunctions.py, 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/__init__.py", line 37, in <module>\n from tensorflow.core.framework.graph_pb2 import *\n File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/graph_pb2.py", line 8, in <module>\n from google.protobuf import reflection as _reflection\n File "/usr/local/lib/python2.7/dist-packages/google/protobuf/reflection.py", 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/python_message.py", line 53, in <module>\n from io import BytesIO\n File "/home/cchang11/anaconda2/lib/python2.7/io.py", line 51, in <module>\n import _io\nImportError: /home/cchang11/anaconda2/lib/python2.7/ The stack of functions is:

Buildings.Utilities.IO.Python27.Functions.BaseClasses.exchange Buildings.Utilities.IO.Python27.Functions.exchange Buildings.Utilities.IO.Python27.Functions.exchange("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 libpython2.7.so? 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
2

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

Did you set the PYTHONPATH as described in http://simulationresearch.lbl.gov/mod... 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 libpython2.7.so as long as you use 32 bit.

edit flag offensive delete link more

Comments

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 libpython2.7.so(64bit) 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 -0600 )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 https://github.com/lbl-srg/modelica-b...

Michael Wetter gravatar imageMichael Wetter ( 2016-02-02 20:54:30 -0600 )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 -0600 )edit
Michael Wetter gravatar imageMichael Wetter ( 2016-02-05 11:09:21 -0600 )edit

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

world2005 gravatar imageworld2005 ( 2016-02-06 19:18:52 -0600 )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

Stats

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

Seen: 338 times

Last updated: Jan 27 '16