I am trying to connect NetLogo from Python. I am following the official pyNetLogo documentation. Here is my code.
import pynetlogo
netlogo = pynetlogo.NetLogoLink(
gui=True,
netlogo_home="/home/protik/NetLogo/"
)
netlogo.load_model("../Netlogo-model/ICS1023.nlogo")
netlogo.command("setup")
It starts the NetLogo interface but fails to run the NetLogo model. It throws this following error.
Exception
Traceback (most recent call last)
File NetLogoLink.java:121, in netLogoLink.NetLogoLink.loadModel()
Exception: Java Exception
The above exception was the direct cause of the following exception:
java.lang.RuntimeException
Traceback (most recent call last)
File ~/anaconda3/envs/netlogo-env/lib/python3.8/site-packages/pynetlogo/core.py:246,
in NetLogoLink.load_model(self, path)
245 try:
--> 246 self.link.loadModel(path)
247 except jpype.JException as ex:
java.lang.RuntimeException: java.lang.RuntimeException
During handling of the above exception, another exception occurred:
NetLogoException
Traceback (most recent call last) Cell In[1], line 8
1 import pynetlogo
3 netlogo = pynetlogo.NetLogoLink(
4 gui=True,
5 netlogo_home="/home/protik/NetLogo/"
6 )
----> 8 netlogo.load_model("../Netlogo-model/ICS1023.nlogo")
9 netlogo.command("setup")
File ~/anaconda3/envs/netlogo-env/lib/python3.8/site-packages/pynetlogo/core.py:249,
in NetLogoLink.load_model(self, path)
247 except jpype.JException as ex:
248 print(ex.stacktrace())
--> 249 raise NetLogoException(str(ex))
NetLogoException: java.lang.RuntimeException
On the NetLogo interface a dialogue box pops up and shows the following line.
error in loading model java.lang.reflect.invocationtargetexception
By the way, the netlogo model itself runs fine. It only creates error while running from Python. I have checked jvm_path which seems to be correct.
/usr/lib/jvm/java-11-openjdk-amd64/lib/server/libjvm.so
What could be the solution?