先说明一下软件版本
neo4j==3.5
出现的问题:用py2neo创建节点时报如下错误(在我的电脑运行是没问题的,换了台电脑就出错了)
py2neo.database.ClientError: SyntaxError: Invalid input ‘_’: expected whitespace, comment, NodeLabel, MapLiteral, a parameter, a parameter (old syntax), a relationship pattern, ‘,’, FROM GRAPH, CONSTRUCT, LOAD CSV, START, MATCH, UNWIND, MERGE, CREATE UNIQUE, CREATE, SET, DELETE, REMOVE, FOREACH, WITH, CALL, RETURN, UNION, ‘;’ or end of input (line 1, column 60 (offset: 59))
排除了py2neo和neo4j版本不匹配的问题
最后通过测试,发现新建了一个py文件运行同样的代码就没问题了
D:\pytest\venv\Scripts\python.exe C:/Users/34845/Desktop/篮球kg/知识图谱构建.py
Traceback (most recent call last):
File "C:\Users\34845\AppData\Local\Programs\Python\Python311\Lib\site-packages\py2neo\internal\connectors.py", line 372, in run
raw_result = hydrator.hydrate_result(r.data.decode("utf-8"))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\34845\AppData\Local\Programs\Python\Python311\Lib\site-packages\py2neo\internal\hydration\__init__.py", line 433, in hydrate_result
raise HydrationError(*data["errors"])
py2neo.internal.hydration.HydrationError: {'code': 'Neo.ClientError.Statement.SyntaxError', 'message': 'Invalid input \'_\': expected whitespace, comment, NodeLabel, MapLiteral, a parameter, a parameter (old syntax), a relationship pattern, \',\', FROM GRAPH, CONSTRUCT, LOAD CSV, START, MATCH, UNWIND, MERGE, CREATE UNIQUE, CREATE, SET, DELETE, REMOVE, FOREACH, WITH, CALL, RETURN, UNION, \';\' or end of input (line 1, column 60 (offset: 59))\r\n"UNWIND $x AS data MERGE (_:node {name:data[0]}) SET _: SET _ = data[1] RETURN id(_)"\r\n ^'}
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\34845\Desktop\篮球kg\知识图谱构建.py", line 32, in <module>
graph.merge(start_node, "node", "name") #"title"是标签
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\34845\AppData\Local\Programs\Python\Python311\Lib\site-packages\py2neo\database.py", line 469, in merge
tx.merge(subgraph, label, *property_keys)
File "C:\Users\34845\AppData\Local\Programs\Python\Python311\Lib\site-packages\py2neo\database.py", line 975, in merge
merge(self, primary_label, primary_key)
File "C:\Users\34845\AppData\Local\Programs\Python\Python311\Lib\site-packages\py2neo\data.py", line 618, in __db_merge__
merge_subgraph(tx, self, primary_label, primary_key)
File "C:\Users\34845\AppData\Local\Programs\Python\Python311\Lib\site-packages\py2neo\internal\operations.py", line 167, in merge_subgraph
for i, identity in enumerate(identities):
File "C:\Users\34845\AppData\Local\Programs\Python\Python311\Lib\site-packages\py2neo\internal\operations.py", line 105, in _merge_nodes
for record in tx.run(cypher, x=data):
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\34845\AppData\Local\Programs\Python\Python311\Lib\site-packages\py2neo\database.py", line 823, in run
return Cursor(self.connector.run(statement=cypher,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\34845\AppData\Local\Programs\Python\Python311\Lib\site-packages\py2neo\internal\connectors.py", line 377, in run
raise GraphError.hydrate(e.args[0])
py2neo.database.ClientError: SyntaxError: Invalid input '_': expected whitespace, comment, NodeLabel, MapLiteral, a parameter, a parameter (old syntax), a relationship pattern, ',', FROM GRAPH, CONSTRUCT, LOAD CSV, START, MATCH, UNWIND, MERGE, CREATE UNIQUE, CREATE, SET, DELETE, REMOVE, FOREACH, WITH, CALL, RETURN, UNION, ';' or end of input (line 1, column 60 (offset: 59))
"UNWIND $x AS data MERGE (_:node {name:data[0]}) SET _: SET _ = data[1] RETURN id(_)"
^
Process finished with exit code 1