janusgraph简单使用、python连接

1.gremlin控制台访问:

(1)E:\janusgraph\janusgraph-0.3.1-hadoop2\elasticsearch\bin中打开elasticsearch.bat

(2)E:\janusgraph\janusgraph-0.3.1-hadoop2\bin打开gremlin.bat

启动成功,在gremlin.bat中使用gremlin语言对janusgraph进行控制操作。

2.通过python连接:

(1)修改gremlin-server.yaml配置文件:

修改位置如图。

(2)修改janusgraph-berkeleyje-es-server.properties:

把janusgraph-berkeleyje-es-server.properties里面的index.search.hostname改为127.0.0.1。

 (3)安装gremlinpython

在anacoda prompt中输入

pip install gremlinpyton

 gremlinpython版本需要适应janusgraph和python的版本,否则会出错,例如我用的janusgraph-0.3.1只能适配3.3.3:

pip install gremlinpython==3.3.3

安装版本错误只需要卸载重装即可:

pip uninstall gremlinpython

(4)连接Python时,需要依次启动es.bat、gremlin.bat、gremlin-server.bat从而远程访问,之后打开pycharm新建脚本:

from gremlin_python import statics
from gremlin_python.structure.graph import Graph
from gremlin_python.process.graph_traversal import __
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
graph = Graph()
connection = DriverRemoteConnection('ws://localhost:8182/gremlin', 'g')
# The connection should be closed on shut down to close open connections with connection.close()
g = graph.traversal().withRemote(connection)
# Reuse 'g' across the application

herculesAge = g.V().has('name', 'hercules').values('age').next()
print('Hercules is {} years old.'.format(herculesAge))
connection.close()

ws://localhost:8182/gremlin这个地址是在本机上使用。

至此,可以用python访问操作janusgraph了。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值