win10 安装neo4j,python连接

1,安装java jdk,具体不在叙述
C:\Users\RoseC>java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
2,下载neo4j图数据库,通常采用社区版本,地址,也可以到官网下载详细的版本
3,配置环境变量并启动,下载后将C:\Software\neo4j-community-3.5.9\bin地址添加到系统的环境变量,然后执行如下脚本启动,且采用管理员权限
neo4j.bat console

然后访问,http://localhost:7474,第一次登陆密码为,neo4j。且登录后需要修改登陆密码

4,安装相关的python包
pip install neo4j neo4j-driver
5,python程序连接
# -*- coding: utf-8 -*-  
from neo4j import GraphDatabase

driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "123456"))

def add_friend(tx, name, friend_name):
    tx.run("MERGE (a:Person {name: $name}) "
           "MERGE (a)-[:KNOWS]->(friend:Person {name: $friend_name})",
           name=name, friend_name=friend_name)

def print_friends(tx, name):
    for record in tx.run("MATCH (a:Person)-[:KNOWS]->(friend) WHERE a.name = $name "
                         "RETURN friend.name ORDER BY friend.name", name=name):
        print(record["friend.name"])

with driver.session() as session:
    session.write_transaction(add_friend, "Arthur", "Guinevere")
    session.write_transaction(add_friend, "Arthur", "Lancelot")
    session.write_transaction(add_friend, "Arthur", "Merlin")
    session.read_transaction(print_friends, "Arthur")

# 结果如下
C:\Users\RoseC\Anaconda3_py_3_6\envs\common01\python.exe F:/project/NLP/QASystemOnMedicalKG/test/test02.py
Guinevere
Lancelot
Merlin

图数据库创建的关系如下图所示:
win10 安装neo4j,python连接

上一篇:关于friend友元的注意事项


下一篇:学习英文-学以致用【场景:请客吃饭】