GreenDelta/openlca-python-tutorial

cannot import from org.openlca.app

Opened this issue · 3 comments

I am trying to import from org.openlca.app to be able to build product system but get the error message

 ImportError: No module named app

Apparently I don't have the module but where do I get it?
Importing from org.openlca.core is no problem.

Everything under the org.openlca.app package is related to the openLCA application with user interface (so everything in the olca-app repository). The other packages (core, io, ...) contain the functionality that is
independent from the user interface (everything in the olca-modules repository).

Thus, a script that uses the org.openlca.app package needs to be executed within the openLCA application (so in the Python editor of openLCA) as it has dependencies to the application framework (Eclipse RCP). There are maybe classes in the app package that could be useful without the user interface. If you want to use them you need to add the org folder in the openLCA/plugins/olca-app_<version> directory to the Python path. Also, you maybe need to add more libraries from the plugins folder.

Thanks for the instructions. I added the org folder and imported

from org.openlca.app.db import Cache

When I now call

a = Cache.getMatrixCache()

the method returns nothing, a is empty (None). But I don't get any error message saying that importing Cache went wrong.

print(Cache)

returns

<type 'org.openlca.app.db.Cache'>

Any ideas where the error might be?

The Cache just holds the matrix and entity cache of the application to faster load things in the user interface. It has a static method to initialize it: Cache.create(db). When you call this then the method Cache.getMatrixCache() should return something.