用python连接数据库neo4j出现错误ImportError: cannot import name 'SocketAddress' from 'neo4j.addressing' (D:\anaconda\lib\site-packages\neo4j\addressing.py)
软件版本neo4j:4.2.15
python3.7
javase:15.0
代码如下:from py2neo import Graph, Node, Relationship
import pandas as pd
import re
import os
def create_relationship(self, start_node, end_node, edges, rel_type, rel_name):
"""
创建实体关系边
:param start_node:
:param end_node:
:param edges:
:param rel_type:
:param rel_name:
:return:
"""
count = 0
# 去重处理
set_edges = []
for edge in edges:
set_edges.append('###'.join(edge))
all = len(set(set_edges))
for edge in set(set_edges):
edge = edge.split('###')
p = edge[0]
q = edge[1]
query = "match(p:%s),(q:%s) where p.name='%s'and q.name='%s' create (p)-[rel:%s{name:'%s'}]->(q)" % (
start_node, end_node, p, q, rel_type, rel_name)
try:
self.graph.run(query)
count += 1
print(rel_type, count, all)
except Exception as e:
print(e)
return
if __name__ == "__main__":
handler = MedicalGraph()
handler.create_graphNodes()
handler.create_graphRels()
报错如下:Traceback (most recent call last):
File "D:\anaconda\lib\site-packages\py2neo\database.py", line 88, in __new__
inst = cls._instances[key]
KeyError: '6fc7d439c7d566b2167c91a9b454580d'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:/pycharmpractice/kbqa_code/QASystemOnMedicalGraph-master/QASystemOnMedicalGraph-master/build_graph.py", line 201, in <module>
handler = MedicalGraph()
File "D:/pycharmpractice/kbqa_code/QASystemOnMedicalGraph-master/QASystemOnMedicalGraph-master/build_graph.py", line 13, in __init__
self.graph = Graph("http://localhost:7474", username="neo4j", password="")
File "D:\anaconda\lib\site-packages\py2neo\database.py", line 298, in __new__
database = Database(uri, **settings)
File "D:\anaconda\lib\site-packages\py2neo\database.py", line 92, in __new__
from py2neo.internal.http import HTTPDriver, HTTPSDriver
File "D:\anaconda\lib\site-packages\py2neo\internal\http.py", line 26, in <module>
from neo4j.addressing import SocketAddress
ImportError: cannot import name 'SocketAddress' from 'neo4j.addressing' (D:\anaconda\lib\site-packages\neo4j\addressing.py)