openlca-python-tutorial
openlca-python-tutorial copied to clipboard
How to run OpenLCA from outside without Eclipse
I would like to run OpenLCA from outside via the python (jython) interface. But how do I do this if I don't use Eclipse? If I am correct I need to append some openlca jar files something like this
import sys
sys.path.append("C:\\Program Files (x86)\\openLCA\\plugins\\olca-app_1.6.3\\libs\\commons-logging-1.1.1.jar"
But which ones do I need to import certain functionality and is this even the right way to do it? It would be very helpful if there was a provided example.
You can just load all the libraries in the openLCA/plugins/olca-app-<version>/libs
folder:
import os
import sys
# change this path so that it matches the `libs` folder of your openLCA installation
OLCA_LIB_DIR = "C:/Users/ms/Downloads/tests/openlca_1.6.3/plugins/olca-app_1.6.3/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)
# now you can access the openLCA API
# ... running an example from another question
from org.openlca.ecospold.io import DataSetType, EcoSpoldIO
import java.io.File as File
xml_file = File("C:/Users/ms/Downloads/spold1.xml")
processes = EcoSpoldIO.readFrom(xml_file, DataSetType.PROCESS)
for ds in processes.dataset:
print(ds.metaInformation.processInformation.referenceFunction.name)
When you have the Jython interpreter installed you can then run such a file via jython myscript.py
from the command line.
let's keep this question open because the issues in this repo are more a faq
Hi all!
I am just running the above steps through the Jython interpreter with the example and it works fine. However, I would like to establish connection with the openlca, do some changes and and upload the file again in the openlca. I 'imported olca' and I added the client = olca.Client(8080) on the above code, but I get a msg 'No module named olca'.
Many thanks.