+1 vote
1.1k views
Hi,

Recently I have downloaded openLCA 2.0.4 and tried to run these lines with OpenLCA IPC server & olca-ipc in python:

------------------------------------

import olca

import uuid

client = olca.Client(8080)

all_processes = client.get_descriptors(olca.Process)

for thispros in all_processes:

    print(thispros.name)

------------------------------------

I keep getting this kind of error:

ERROR:root:failed to get descriptors of type <class 'olca.schema.XXX'>: -32601: Does not understand: get/descriptors

I have switch from Process to Flow Property, ProductSystem, and keep getting errors like this:

ERROR:root:failed to get descriptors of type <class 'olca.schema.FlowProperty'>: -32601: Does not understand: get/descriptors

ERROR:root:failed to get descriptors of type <class 'olca.schema.Unit'>: -32601: Does not understand: get/descriptors

ERROR:root:failed to get descriptors of type <class 'olca.schema.FlowProperty'>: -32601: Does not understand: get/descriptors

ERROR:root:failed to get descriptors of type <class 'olca.schema.ProductSystem'>: -32601: Does not understand: get/descriptors

------------------------------------

But then when I switch back to openLCA 1.11.0, it worked again without running into those errors.

What has changed since version 1 and what should I change so that my python code will work with OpenLCA 2.X?

Thank you!
in openLCA by (170 points)

1 Answer

+3 votes
by (630 points)
selected by
 
Best answer

For using olca-ipc with openLCA 2.x, you will need to upgrade the version of your olca-ipc package and import it as "olca_ipc".

Moreover, some of the functions have been moved from olca-ipc to the olca-schema library, which you can import via "olca_schema".

In order to print the process names in your example above, the following code works for me:

import olca_ipc as ipc
import olca_schema as o
 
client = ipc.Client(8080)
 
all_processes = client.get_descriptors(o.Process)
for thispros in all_processes:
    print(thispros.name)
As you can see, the object "Process" is accessed via the olca-schema library.
You will probably need to modify your code for it to work with openLCA 2.x.
Kind regards

by (170 points)
Thank you! I will try it out!
by (170 points)
It seems I have already installed the latest version of olca ipc and olca schema

python -m pip install olca-ipc
Requirement already satisfied: olca-ipc in c:\users\demonaica\appdata\local\programs\python\python310\lib\site-packages (0.0.12)
Requirement already satisfied: requests in c:\users\demonaica\appdata\local\programs\python\python310\lib\site-packages (from olca-ipc) (2.31.0)
Requirement already satisfied: charset-normalizer<4,>=2 in c:\users\demonaica\appdata\local\programs\python\python310\lib\site-packages (from requests->olca-ipc) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in c:\users\demonaica\appdata\local\programs\python\python310\lib\site-packages (from requests->olca-ipc) (3.6)
Requirement already satisfied: urllib3<3,>=1.21.1 in c:\users\demonaica\appdata\local\programs\python\python310\lib\site-packages (from requests->olca-ipc) (2.1.0)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\demonaica\appdata\local\programs\python\python310\lib\site-packages (from requests->olca-ipc) (2023.11.17)

python -m pip install olca-schema
Requirement already satisfied: olca-schema in c:\users\demonaica\appdata\local\programs\python\python310\lib\site-packages (0.0.12)


I still caught an error using the script you just posted:

Traceback (most recent call last):
  File "C:\Users\demonaica\Desktop\Project\Quickstarter_DSE_DesktopMachine\8_playground3_MatChange_KPI_3D_wSim_CHEXA8_olca_new3_test_openlca2\test.py", line 1, in <module>
    import olca_ipc as ipc
ModuleNotFoundError: No module named 'olca_ipc'
by (14.0k points)
Probably, you need to upgrade the ipc module: `python -m pip install --upgrade olca-ipc`
by (170 points)
I am using Python 3.10.10 but openLCA >= 2 requires Python >= 3.11. I guess that's the reason. Thank you!
...