Windows
参考:https://blog.csdn.net/qq_38335648/article/details/115027676
环境配置
安装包 | 版本 | 路径 |
---|---|---|
Python | - | - |
JDK | 8u301 | https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html |
Neo4j | Community 4.3.3 | https://neo4j.com/download-center/#community |
py2neo | 4.1 | pip install py2neo==4.1 |
问题
1、有问题就降低版本
2、pip 不了 py2neo,更新pip:python -m pip install --upgrade pip
3、报错:cannot import name 'clock' from 'time' (unknown location)
, 参考:https://coding.imooc.com/learn/questiondetail/226238.html
Ubuntu
参考:https://blog.csdn.net/fi_hu/article/details/117210156
环境配置
安装包 | 版本 | 路径 |
---|---|---|
Python | - | - |
JDK | - | sudo apt-get install default-jdk |
Neo4j | 4.3.3 | https://neo4j.com/download-center/#community , tar -xf /filename |
py2neo | 4.1 | pip install py2neo==4.1 , pip install neo4j=4.3 , pip install neo4j-driver |
问题
1、有问题就降低版本
Code (Win 和 ubuntu 一样)
参考:https://blog.csdn.net/RHJlife/article/details/108586578/
import csv
import py2neo
from py2neo import Graph, Node, Relationship, NodeMatcher
# 密码改成自己的
g = Graph('http://localhost:7474', username='neo4j', password='myneo') # 链接到浏览器
# 数据文件替换成自己的
with open('RedHouseDream.csv', 'r', encoding='gbk') as f:
reader = csv.reader(f)
for item in reader:
if reader.line_num==1:
continue
print("current line: ", reader.line_num, 'current content: ', item)
startNode = Node("Person", name=item[0])
endNode = Node("Person", name=item[1])
relation = Relationship(startNode, item[3], endNode)
# g.merge(startNode, "Person", "name")
# g.merge(endNode, "Person", "name")
g.merge(relation, "Person", "name")
注意事项
1、windows下需要先启动neo4j,neo4j.bat console
(已添加到系统环境变量)
2、http://localhost:7474/browser/
默认只显示25个entity,在左下角可设置
3、数据源可在http://www.openkg.cn/dataset/ch4masterpieces
下载