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

Python SDK Bindings for OpenStudio

asked 2014-12-15 12:36:36 -0500

updated 2017-08-15 13:44:30 -0500

I'm trying to use the Python bindings for the OpenStudio SDK. I've gone through the instructions on the OpenStudio Wiki for developers and have used CMake and Visual Studio Express to compile the source code from the Github repository. I compiled the ALL_BUILD in the OpenStudioCore solution as Release x64. I've added "<\path_to_openstudio>\Openstudio-1.5.3\build\OSCore-prefix\src\OSCore-build\Products\python\Release" to my PythonPath.

When I test a module import in Python:

import openstudioairflow

I get the following error message:

Traceback (most recent call last):
File "stdin", line 1, in <module>

File "<\path_to_openstudio>\Openstudio-1.5.3\build\OSCore-prefix\src\OSCore-build\Products\python\Release\openstudioairflow.py", line 28, in module _openstudioairflow = swig_import_helper() File

File "<\path_to_openstudio>\Openstudio-1.5.3\build\OSCore-prefix\src\OSCore-build\Products\python\Release\openstudioairflow.py", line 24, in swig_import_helper _mod = imp.load_module('_openstudioairflow', fp, pathname, description)

ImportError: DLL load failed: The specified module could not be found.

It appears to be an error in the SWIG link to the DLLs. The Release folder contains .py, .pyd, and .exp files. I do not see any .DLL files, but there were no compiler errors.

Is there an additional step that I am missing in compiling or configuring the bindings?

edit retag flag offensive close merge delete

Comments

@Mark Adams might be able to help

aparker's avatar aparker  ( 2014-12-15 13:27:48 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted
7

answered 2014-12-15 19:34:35 -0500

updated 2014-12-15 19:41:33 -0500

I agree with @macumber, this seems like a path issue.

There are a few things you can do to try and get the bindings working.

First, I use PyCharm when working with Python in general and the OpenStudio bindings. It provides code completion and insights, even for the OpenStudio bindings, among many other benefits and there is a free community version.

Next, I create an 'openstudio' package, basically a folder with an __init__.py file. This allows you to import openstudio and use it like m = openstudio.model.Model(). Within this package, I put all the .py and .pyd files from the /python and /python/Release folders.

Now a major caveat to this is that the .pyd files contain a dependency reference to the associated .dll (located in Products/Release/). This means that any time you recompile OpenStudio then you will need to put the new .pyd and .py files in your 'openstudio' package otherwise you will probably get errors in your python bindings.

One way around this issue is to create a package of OpenStudio using the BUILD_PACKAGE option in CMake. This will then create a 'python/openstudio' folder with all the .py, .pyd, and .dll files in it with the correct dependency references.

So the 'openstudio' package has the following (rough) contents..

-- openstudio
   -  __init__.py
   -  openstudiomodel.py
   -  etc...
   -  _openstudiomodel.pyd
   -  etc...
   -  openstudio_model.dll (if using BUILD_PACKAGE)
   -  etc...

The __init__.py file looks like ...

import openstudiomodel as model
import openstudioenergyplus as energyplus
from openstudioutilitiescore import *
etc...

Then use it like the following import design day file example...

from openstudio import model, Workspace, path, energyplus
m = model.Model()
ddy_path = "/Applications/EnergyPlus-8-0-0/WeatherData/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.ddy"
os_ddy_path = path(ddy_path)
ddy_idf = IdfFile.load(os_ddy_path)
ddy_workspace = Workspace(ddy_idf.get())
reverse_translator = energyplus.ReverseTranslator()
ddy_model = reverse_translator.translateWorkspace(ddy_workspace)
ddy_objects = [ddy_object for ddy_object in model.getDesignDays(ddy_model) if (".4%" in ddy_object.name().get() or "99.6" in ddy_object.name().get())]
m.addObjects(ddy_objects)

Hopefully this helps (and makes sense). Also, these code snippets work for python 2.7 and probably should work in python 3 but that is untested.

edit flag offensive delete link more

Comments

4

Just so everyone knows, Mark is the unofficial guru and maintainer of the Python bindings. We can thank him for getting things this far in the Python world. He has done this on a volunteer basis.

Kyle Benne's avatar Kyle Benne  ( 2014-12-15 21:40:53 -0500 )edit

I am having the same issue with Linux bindings... that they wont load, does anyone have a list of dependencies for Linux?

Arif Hanif's avatar Arif Hanif  ( 2016-03-25 19:08:19 -0500 )edit
3

answered 2015-01-30 10:25:24 -0500

dan.glassman's avatar

updated 2017-02-07 04:50:58 -0500

I got to this same point, same error -- using python 2.7 / win32. I copied the .dll files from build\OSCore-prefix\src\OSCore-build\Products\Release into the same directory as the .py and .pyd, and the import then succeeded.

This worked well for x64, too.

edit flag offensive delete link more
3

answered 2014-12-15 14:16:50 -0500

updated 2017-02-07 04:50:34 -0500

This looks like it is likely a path issue. I would suggest modifying your path so the OpenStudio dlls (including Qt and the other dependencies) as well as the OpenStudio Python Wrapper dlls are first in your path. If you are on Windows I would suggest using DependencyWalker to determine which libraries are not loading correctly. There are some minimal instructions here.

Glad you were able to get the Python bindings compiling, that is a great start!

edit flag offensive delete link more

Your Answer

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

Add Answer

Careers

Question Tools

3 followers

Stats

Asked: 2014-12-15 12:36:36 -0500

Seen: 1,543 times

Last updated: Feb 07 '17