Import error when using the python API
Posted: 13 Sep 2017 12:29
Hi,
I'm testing out the openLCA python API and I really hope I can soon run calculations in bulk through it.
I'm starting slowly, using the openLCA python tutorial on GitHub (many thanks for that). I'm trying to use the functions defined in util.py in the GitHub repo.
I copied the file util.py on my computer under /Users/mathieusa/openLCA-data-1.4/python and I'm running a script in the python-developer-tool-console in openLCA 1.4.2 on Mac OS X Yosemite (10.10.5).
I get an import error. Please see the log below.
Note: the same import error happens if I run "from org.openlca.core.database import Daos" directly in the python console in openLCA.
Can someone point me to what I'm doing wrong?
Best wishes,
Mathieu
python script:
log file:
I'm testing out the openLCA python API and I really hope I can soon run calculations in bulk through it.
I'm starting slowly, using the openLCA python tutorial on GitHub (many thanks for that). I'm trying to use the functions defined in util.py in the GitHub repo.
I copied the file util.py on my computer under /Users/mathieusa/openLCA-data-1.4/python and I'm running a script in the python-developer-tool-console in openLCA 1.4.2 on Mac OS X Yosemite (10.10.5).
I get an import error. Please see the log below.
Note: the same import error happens if I run "from org.openlca.core.database import Daos" directly in the python console in openLCA.
Can someone point me to what I'm doing wrong?
Best wishes,
Mathieu
python script:
Code: Select all
from org.openlca.core.database.derby import DerbyDatabase as Db
from java.io import File
import org.openlca.core.model as model
from org.openlca.core.database import ProcessDao
import util
if __name__ == '__main__':
db_dir = File('/Users/mathieusa/openLCA-data-1.4/databases/phd_ei22_ist_test')
db = Db(db_dir)
flow = util.find(db, model.Flow, 'Electricity, wind, onshore, MIX IST')
log file:
Code: Select all
49199005 Worker-28 ERROR org.openlca.app.devtools.python.Python failed to evaluate script
Traceback (most recent call last):
File "<string>", line 44, in <module>
File "/Users/mathieusa/openLCA-data-1.4/python/util.py", line 1, in <module>
from org.openlca.core.database import Daos
ImportError: cannot import name Daos
at org.python.core.Py.ImportError(Py.java:300)
at org.python.core.imp.importFromAs(imp.java:1052)
at org.python.core.imp.importFrom(imp.java:1016)
at util$py.f$0(/Users/mathieusa/openLCA-data-1.4/python/util.py:52)
at util$py.call_function(/Users/mathieusa/openLCA-data-1.4/python/util.py)
at org.python.core.PyTableCode.call(PyTableCode.java:166)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.imp.createFromCode(imp.java:393)
at org.python.core.imp.createFromSource(imp.java:356)
at org.python.core.imp.loadFromSource(imp.java:583)
at org.python.core.imp.find_module(imp.java:480)
at org.python.core.imp.import_next(imp.java:737)
at org.python.core.imp.import_module_level(imp.java:856)
at org.python.core.imp.importName(imp.java:946)
at org.python.core.ImportFunction.__call__(__builtin__.java:1301)
at org.python.core.PyObject.__call__(PyObject.java:373)
at org.python.core.__builtin__.__import__(__builtin__.java:1254)
at org.python.core.imp.importOne(imp.java:965)
at org.python.pycode._pyx15.f$0(<string>:51)
at org.python.pycode._pyx15.call_function(<string>)
at org.python.core.PyTableCode.call(PyTableCode.java:166)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1312)
at org.python.core.Py.exec(Py.java:1356)
at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:222)
at org.openlca.app.devtools.python.Python.doEval(Unknown Source)
at org.openlca.app.devtools.python.Python.eval(Unknown Source)
at org.openlca.app.devtools.python.PythonEditor.lambda$0(Unknown Source)
at org.openlca.app.devtools.python.PythonEditor$$Lambda$36/961994506.run(Unknown Source)
at org.openlca.app.WrappedJob.run(Unknown Source)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)