如何让GremlinPython与gremlinserver3.4.3一起工作?

2024-10-05 10:16:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我的环境是:

java -version
java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)

python3 --version
Python 3.7.4

这应该是唯一相关的环境部分。不幸的是,我使用MacOS和使用macports可能会有所不同,这不应该是一个问题。在

我刚刚在ubuntu18.04lts上测试了seehttp://wiki.bitplan.com/index.php/Gremlin_python#Installlation_automation,结果是一样的。在

所以我想试试小Python。 我找到了https://pypi.org/project/gremlinpython/ 高兴地补充道

^{pr2}$

给我的要求.txt在

sudo -H pip install -r requirements.txt

跑得很成功-太好了。 让我们找到一些python代码。在

https://gist.githubusercontent.com/okram/f193d5616563a69ad5714a42c504276f/raw/b8075410e400e18f18360015945f3760d99d044a/gremlin-python-play.py

有了。在

哦-我需要一个服务器。。。在

我们来下载吧

http://ftp-stud.hs-esslingen.de/pub/Mirrors/ftp.apache.org/dist/tinkerpop/3.4.3/apache-tinkerpop-gremlin-server-3.4.3-bin.zip

解压缩并为其创建一个启动文件,如上面的示例所示:

gspath=$HOME/Downloads/apache-tinkerpop-gremlin-server-3.4.3
#$gspath/bin/gremlin-server.sh install org.apache.tinkerpop gremlin-python 3.4.3
$gspath/bin/gremlin-server.sh $gspath/conf/gremlin-server-modern-py.yaml

它不工作-从龙卷风得到599超时。在

看看:

Why can't I connect to Gremlin-Server?

尝试提示,例如使用0.0.0.0作为主机

检查启动。在

抱歉-出现错误:

Could not initialize gremlin-jython GremlinScriptEngine as init script could not be evaluated
java.util.concurrent.CompletionException: java.lang.IllegalArgumentException: gremlin-jython is not an available GremlinScriptEngine
    at java.util.concurrent.CompletableFuture.reportJoin(CompletableFuture.java:375)
    at java.util.concurrent.CompletableFuture.join(CompletableFuture.java:1934)
    at org.apache.tinkerpop.gremlin.server.util.ServerGremlinExecutor.lambda$new$4(ServerGremlinExecutor.java:141)
    at java.util.LinkedHashMap$LinkedKeySet.forEach(LinkedHashMap.java:559)
    at org.apache.tinkerpop.gremlin.server.util.ServerGremlinExecutor.<init>(ServerGremlinExecutor.java:136)
    at org.apache.tinkerpop.gremlin.server.GremlinServer.<init>(GremlinServer.java:122)
    at org.apache.tinkerpop.gremlin.server.GremlinServer.<init>(GremlinServer.java:86)
    at org.apache.tinkerpop.gremlin.server.GremlinServer.main(GremlinServer.java:345)
Caused by: java.lang.IllegalArgumentException: gremlin-jython is not an available GremlinScriptEngine
    at org.apache.tinkerpop.gremlin.jsr223.CachedGremlinScriptEngineManager.registerLookUpInfo(CachedGremlinScriptEngineManager.java:95)
    at org.apache.tinkerpop.gremlin.jsr223.CachedGremlinScriptEngineManager.getEngineByName(CachedGremlinScriptEngineManager.java:58)
    at org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor.lambda$eval$0(GremlinExecutor.java:266)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
[WARN] ServerGremlinExecutor - Could not initialize gremlin-python GremlinScriptEngine as init script could not be evaluated
java.util.concurrent.CompletionException: java.lang.IllegalArgumentException: gremlin-python is not an available GremlinScriptEngine
    at java.util.concurrent.CompletableFuture.reportJoin(CompletableFuture.java:375)
    at java.util.concurrent.CompletableFuture.join(CompletableFuture.java:1934)
    at org.apache.tinkerpop.gremlin.server.util.ServerGremlinExecutor.lambda$new$4(ServerGremlinExecutor.java:141)
    at java.util.LinkedHashMap$LinkedKeySet.forEach(LinkedHashMap.java:559)
    at org.apache.tinkerpop.gremlin.server.util.ServerGremlinExecutor.<init>(ServerGremlinExecutor.java:136)
    at org.apache.tinkerpop.gremlin.server.GremlinServer.<init>(GremlinServer.java:122)
    at org.apache.tinkerpop.gremlin.server.GremlinServer.<init>(GremlinServer.java:86)
    at org.apache.tinkerpop.gremlin.server.GremlinServer.main(GremlinServer.java:345)
Caused by: java.lang.IllegalArgumentException: gremlin-python is not an available GremlinScriptEngine
    at org.apache.tinkerpop.gremlin.jsr223.CachedGremlinScriptEngineManager.registerLookUpInfo(CachedGremlinScriptEngineManager.java:95)
    at org.apache.tinkerpop.gremlin.jsr223.CachedGremlinScriptEngineManager.getEngineByName(CachedGremlinScriptEngineManager.java:58)
    at org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor.lambda$eval$0(GremlinExecutor.java:266)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

gremlin-python is not an available GremlinScriptEngine

提到应该安装服务器插件。我早就料到了

$gspath/bin/gremlin-server.sh install org.apache.tinkerpop gremlin-python 3.4.3

会这样做,当我再次运行它时,我得到:

Installing dependency org.apache.tinkerpop gremlin-python 3.4.3
Could not install the dependency: a module with the name gremlin-python is already installed

如何在这里工作?

我将python测试代码缩减为:

# https://pypi.org/project/gremlinpython/

# start GremlinServer
# bin/gremlin-server.sh -i org.apache.tinkerpop gremlin-python 3.2.2-SNAPSHOT
# bin/gremlin-server.sh conf/gremlin-server-modern-py.yaml

# in practice, you really only need the 3 imports below

from gremlin_python import statics
from gremlin_python.structure.graph import Graph
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
# this allows us to do g.V().repeat(out()) instead of g.V().repeat(__.out())-type traversals

#statics.load_statics(globals())

# create a remote connection using RemoteStrategy

graph = Graph()
g = graph.traversal().withRemote(DriverRemoteConnection('ws://localhost:8182','g'))

print (g.V().count().value())

Tags: orgserverinitapacheutilnotjavaconcurrent
3条回答

基于@stephen mallette的努力,我创造了:

https://github.com/WolfgangFahl/gremlin-python-tutorial

详细解释见

http://wiki.bitplan.com/index.php/Gremlin_python

提供基于脚本的安装:

./run -h
usage: ./run  [-h|-i|-s|-c]
  -h| help: show this usage
  -i| install: install prerequisites
  -s| server: start server
  -c| console: start console
  -p| python: start python trial code

它试图自动化必要的步骤

  1. 安装
  2. Gremlin服务器启动
  3. Gremlin控制台启动(用于调试)
  4. Python脚本开始

1。安装

^{pr2}$

安装

  1. gremlin服务器
  2. 小精灵控制台
  3. gremlin python模块

2。Gremlin服务器启动

 ./run -s

在前台用默认的yaml文件启动gremlin服务器

3。Gremlin控制台启动(用于调试)

 ./run -c

启动gremlin控制台

4。Python脚本启动

./run -p

启动python测试脚本。在

# minimal imports
from gremlin_python.process.anonymous_traversal import traversal
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
# get the remote graph traversal
g = traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))
vCount=g.V().count().next()
print("The modern graph has %d vertices" % (vCount))

预期结果:

starting python test code
The modern graph has 6 vertices

以上脚本已经过测试:

  • Ubuntu 18.04 LTS
  • 特拉维斯
  • MacOS和MacPorts

我想你刚刚抓到了一些零碎的代码、脚本和答案,在TinkerPop多年的发展过程中,它们在不同版本上是不匹配的。在

我认为你只需要重新开始并简化。在

  1. 确定最近必须发布的3.4.3版本和downloadGremlin服务器。在
  2. 解压并使用以下命令启动服务器:bin/gremlin-server.sh conf/gremlin-server-modern.yaml,最初尝试以“localhost”的身份从连接,这样就不需要更改配置,并且保持简单。在
  3. 验证是否可以使用Gremlin Console连接到它。在
  4. 现在安装gremlinpython,确保pip使用3.4.3。在

在这一点上,我希望以下代码可以开箱即用:

g=traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))
print (g.V().count().toList())

注意,我用toList()终止了遍历(我注意到您的代码没有这样的terminating step)-没有这个步骤,遍历就不会是{a4}。我不确定这是否是你面临的问题的一部分。在

对于这个命令:

^{pr2}$

如果要将本机python lambda发送到服务器,则只需要运行该命令。虽然这听起来不错,但请记住,如果可能的话,您应该尽量避免使用lambdas,而且python脚本引擎在缓存和执行方面没有Groovy脚本引擎那么健壮。如果一定要使用lambda,那么即使是用Python编写代码,我也会选择Groovy。也就是说,我不知道为什么在服务器启动时会出现错误(fwiw,我实际上用conf/gremlin-server-modern-py.yaml测试了简单的启动,它没有出错)。也许如果你用一个新的设置重试,你会有一个干净的开始。在

一旦建立了基本配置,就可以进行调整,比如修改Gremlin服务器yaml文件中的host配置,以便可以从外部IP地址连接到它。在

我怀疑你已经有了解决这个问题的方法-但是599是我认为的原因,因为除了本地机器设置之外,你无法访问ws-port。我也遇到了类似的问题。在

如果将gremlin yaml中的host属性设置为0.0.0.0-它将侦听所有接口。在localhost上测试所有东西都给了我一种错误的安全感——当我监听所有网络接口时,安全感就起作用了——这反过来又允许我在gremlin服务器上拥有单独的客户端。在

相关问题 更多 >

    热门问题