1

我的环境是:

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 可能会有所不同,这应该不是问题。

我刚刚在 Ubuntu 18.04 LTS 上测试了东西,请参阅http://wiki.bitplan.com/index.php/Gremlin_python#Installlation_automation并且行为是相同的。

所以我想试用 gremlin-python。我找到了https://pypi.org/project/gremlinpython/ 并愉快地添加了

gremlinpython

到我的requirements.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 超时。

看着:

为什么我无法连接到 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 不是可用的 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())
4

3 回答 3

2

我怀疑你已经有一个解决方法 - 但我认为 599 是因为除了本地机器设置之外你无法访问 ws 端口。我在隔离安装时遇到了类似的问题。

如果您将 gremlin yaml 中的主机属性设置为 0.0.0.0 - 它会侦听所有接口。在 localhost 上测试所有东西给了我一种错误的安全感——当我在所有网络接口上监听时都能正常工作——这反过来又让我有单独的客户端到 gremlin 服务器。

于 2019-12-01T17:27:20.507 回答
0

我认为您只是抓取了一些代码、脚本和答案,它们在 TinkerPop 多年演变的各种版本方面是不匹配的。

我认为您只需要重新开始并简化即可。

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

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

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

请注意,我终止了遍历toList()(我注意到您的代码没有这样的终止步骤)-没有该步骤,将不会执行遍历。我不确定这是否是您面临的问题的一部分。

至于这个命令:

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

如果您打算将本机 python lambdas 发送到服务器,则只需要运行它。虽然这听起来很简洁,但请记住,如果可能的话,您应该避免使用 lambda,并且 python ScriptEngine 在缓存和执行方面不如 Groovy 强大。如果您绝对必须使用 lambda,即使您使用 Python 编码,我也更喜欢 Groovy。也就是说,我不确定你为什么在服务器启动时遇到错误(fwiw,我实际上用 the 测试了简单的启动conf/gremlin-server-modern-py.yaml并且它启动时没有错误)。也许如果您使用全新的设置重试,您将获得一个全新的开始。

建立基本配置后,您可以进行调整,例如更改hostGremlin Server yaml 文件中的配置,以便您可以从外部 IP 地址连接到它。

于 2019-09-16T10:44:54.587 回答
0

基于@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-Console 启动(用于调试)
  4. Python脚本启动

1.安装

 run -i

安装

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

2. Gremlin-Server 启动

 ./run -s

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

3. Gremlin-Console 启动(用于调试)

 ./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
于 2019-09-17T13:18:46.427 回答