首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将tinkergraph上传到python/gremlin?

如何将tinkergraph上传到python/gremlin?
EN

Stack Overflow用户
提问于 2018-12-10 22:55:27
回答 1查看 1.9K关注 0票数 1

我正在尝试在python中使用gremlin。我导入了以下内容:

代码语言:javascript
复制
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
from gremlin_python.structure.graph import Graph
from gremlin_python import statics
from gremlin_python.process.graph_traversal import __
from gremlin_python.process.strategies import *
from gremlin_python.process.traversal import *
import asyncio
statics.load_statics(globals()) 

当我运行以下命令时:

代码语言:javascript
复制
graph = TinkerGraph.open() 
graph.io(graphml()).readGraph('air-routes.graphml') 

我得到以下错误:

代码语言:javascript
复制
NameError: name 'TinkerGraph' is not defined

我该如何解决这个问题?

EN

回答 1

Stack Overflow用户

发布于 2018-12-10 23:10:40

Python中没有TinkerGraph。在gremlin-python中,您只能远程获得对服务器上图形的引用,而引用可能是TinkerGraph或其他什么。如果要以这种方式加载数据,则必须通过Client实例以脚本形式发出该命令:

代码语言:javascript
复制
client = Client('ws://localhost:45940/gremlin', 'g')
client.submit("graph.io(graphml()).readGraph('air-routes.graphml');[]").all().result()

其中,脚本中的“图形”是服务器上已经存在的Graph实例(可能是空的)。如果您使用的是Gremlin Server,则可以考虑将该加载作为Gremlin Server startup的一部分单独执行,然后使用gremlin-python来查询该数据。这在本例中可能是最好的,因为数据将仅在服务器启动时出现。

请注意,在3.4.0中,我们引入了io()步骤,它将直接作为gremlin-python的一部分,在这一点上,您将能够直接执行以下操作:

代码语言:javascript
复制
g.io('air-routes.xml').read()

在原生python中,它只会工作(同样,Graph实例必须是远程定义的),尽管文件必须是服务器可读的。

下面是我在Python shell中提交脚本的工作示例,首先使用tornado错误,然后不使用:

代码语言:javascript
复制
$ env/bin/python
Python 3.4.3 (default, Nov 28 2017, 16:41:13) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from gremlin_python.driver.client import Client
>>> client = Client('ws://localhost:8182/gremlin', 'g')
>>> client.submit("g.V()").all().result()
Traceback (most recent call last):
  File "/home/smallette/git/apache/incubator-tinkerpop/gremlin-python/target/python3/gremlin_python/driver/client.py", line 51, in __init__
    from gremlin_python.driver.tornado.transport import (
  File "/home/smallette/git/apache/incubator-tinkerpop/gremlin-python/target/python3/gremlin_python/driver/tornado/transport.py", line 19, in <module>
    from tornado import ioloop, websocket
ImportError: No module named 'tornado'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/smallette/git/apache/incubator-tinkerpop/gremlin-python/target/python3/gremlin_python/driver/driver_remote_connection.py", line 45, in __init__
    password=password)
  File "/home/smallette/git/apache/incubator-tinkerpop/gremlin-python/target/python3/gremlin_python/driver/client.py", line 54, in __init__
    raise Exception("Please install Tornado or pass"
Exception: Please install Tornado or passcustom transport factory
>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit
>>> exit()
$ env/bin/pip install tornado
Collecting tornado
Collecting backports-abc>=0.4 (from tornado)
  Using cached https://files.pythonhosted.org/packages/7d/56/6f3ac1b816d0cd8994e83d0c4e55bc64567532f7dc543378bd87f81cebc7/backports_abc-0.5-py2.py3-none-any.whl
Installing collected packages: backports-abc, tornado
Successfully installed backports-abc-0.5 tornado-5.1.1
smallette@ubuntu:~/git/apache/incubator-tinkerpop/gremlin-python/target/python3$ env/bin/python
Python 3.4.3 (default, Nov 28 2017, 16:41:13) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from gremlin_python import statics
>>> client = Client('ws://localhost:8182/gremlin', 'g')
>>> client.submit("g.V()").all().result()
[v[0]]
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53708193

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档