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

Revision history [back]

Python-Dymola Interacting Issues

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.