Skip to content

Running files to change openLCA values from a jython interpreter. #23

@wardevJ

Description

@wardevJ

I have been attempting to use the update parameter example listed in the code section of this tutorial to make changes to openLCA from a separate jython interpreter. I have attempted to use the code mentioned in answers to the question of how to run openLCA from outside without Eclipse, although this doesn't seem to be working with my version of jython (2.7.2) or openLCA (1.7.4), as it cannot seem to find the openlca module from the import lines:

from org.openlca.core.database.derby import DerbyDatabase
from org.openlca.core.database import ParameterDao

ImportError: No module named openlca

Are there any steps I am missing? Have I got the wrong location for the lib file?

Full code:

import os
import sys

OLCA_LIB_DIR = "C:/Users/wardevj/openlca-data-1.4/html/olca-app/libs"

for jar in os.listdir(OLCA_LIB_DIR):
  print("Add jar to path " + jar)
  full_path = os.path.join(OLCA_LIB_DIR, jar)
  sys.path.append(full_path)

from java.io import File
from org.openlca.core.database.derby import DerbyDatabase
from org.openlca.core.database import ParameterDao

if __name__ == '__main__':
  db_dir = File('C:/Users/wardevj/openLCA-data-1.4/databases/ecoinvent_35_lcia_method_20181210')
  db = DerbyDatabase(db_dir)
  dao = ParameterDao(db)
  param = dao.getForName('test_value')[1]
  param.value = 42.0
  dao.update(param)
  db.close()

Run in jython 2.7.2 interpreter with command execfile("filename.py")

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions