gpt4 book ai didi

python - 通过 Java 网关链接 Netlogo 和 Python

转载 作者:太空狗 更新时间:2023-10-30 02:51:02 25 4
gpt4 key购买 nike

我试图使用 nl4py 通过 java 桥连接 Python 和 Netlogo。在尝试了此处描述的所有操作后,我不断收到错误消息:https://arxiv.org/pdf/1808.03292.pdf .我正在使用 MAC 和 python 2.7。

我也尝试过不使用 nl4py 并直接使用 py4j 手动完成。但是当我尝试调用 from py4j.Java_Gateway import Java_Gateway 时,我得到了错误:

Traceback (most recent call last):
File "/Users/user/Desktop/Machines Model/pythonjavanetlogolink.py", line 1, in <module>
from py4j.Java_Gateway import Java_Gateway
ImportError: No module named Java_Gateway'
import nl4py
import time

nl4py.startServer("/Users/user/Desktop/NetLogo610")

model = "/Users/user/Desktop/Machines Model/ABM4.nlogo"

nl4py.netlogoWorkspaceFactory.deleteAllExistingWorkspaces()

nl4py.netlogoWorkspaceFactory.newNetLogoHeadlessWorkspace()

for workspace in nl4py.netlogoWorkspaceFactory.getAllExistingWorkspaces():
workspace.openModel(model)

nl4py.netlogoWorkspaceFactory.deleteAllExistingWorkspaces()

nl4py.stopServer()
Traceback (most recent call last):
File "/Users/user/Desktop/Machines Model/python_link.py", line 13, in <module>
workspace.openModel(model)
File "/Library/Python/2.7/site-packages/nl4py/NetLogoHeadlessWorkspace.py", line 52, in openModel
self.__bridge.openModel(self.__session,self.__path)
File "/Library/Python/2.7/site-packages/py4j/java_gateway.py", line 1286, in __call__
answer, self.gateway_client, self.target_id, self.name)
File "/Library/Python/2.7/site-packages/py4j/protocol.py", line 328, in get_return_value
format(target_id, ".", name), value)
py4j.protocol.Py4JJavaError: An error occurred while calling t.openModel.
: java.lang.NoSuchMethodError: org.nlogo.headless.HeadlessWorkspace.open(Ljava/lang/String;)V
at nl4py.server.HeadlessWorkspaceController.openModel(HeadlessWorkspaceController.java:133)
at nl4py.server.NetLogoControllerServer.openModel(NetLogoControllerServer.java:100)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at py4j.Gateway.invoke(Gateway.java:282)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:214)
at java.base/java.lang.Thread.run(Thread.java:835)

最佳答案

哇,我真的想放弃并决定尝试不同的 NetLogo 版本并且它成功了。因此,对于遇到相同/相似问题的任何人,请尝试在 NL 6.0.4 或更早版本上运行它。他们更改了最新版本中的一些目录,因此无法正常工作。

关于python - 通过 Java 网关链接 Netlogo 和 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57178584/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com