py2neo: AttributeError: 'function' object has no attribute 'begin'

py2neo: AttributeError: 'function' object has no attribute 'begin'

我正在使用 py2neo 版本 3 并收到以下错误:

> GET http://localhost:7474/db/data/
< 200 OK [795]
Traceback (most recent call last):
  File "run_snomed_upload.py", line 63, in <module>
    sp = SnomedConceptProcessor()
  File "/home/arron/Downloads/Snomed/neo4j/snomed_concept_processor.py", line 18, in __init__
    tx = self.graph.run.begin()                                      # changed .cyhper to .run
AttributeError: 'function' object has no attribute 'begin'

代码:

import re
from string import Template
from py2neo import Graph
from py2neo import watch
from worker.abstract_item_processor import BaseItemProcessor



class SnomedConceptProcessor(BaseItemProcessor):
    statement = Template("CREATE (c:Concept:FSA:$label {conceptId: \"$id\", term: \"$term\", descType: $descType});")
    create_index_concept_id = "CREATE INDEX ON :Concept(conceptId)"
    create_index_term = "CREATE INDEX ON :Concept(term)"

    def __init__(self):
        watch("httpstream")
        self.graph = Graph(super().graph_url)
        tx = self.graph.run.begin() 

我读到如果使用 py2neo v3,那么我需要将 .cypher 更改为 .run,您可以看到我已经完成了。我需要降级到 py2neo v2 吗?如果需要,我该如何在没有并行包的情况下降级?

Cypher.run()是一个接收Cypher语句和参数字典作为参数的函数。您没有将 Cypher.run() 作为函数调用,也没有提供参数。

The docs 说:

Note: The previous version of py2neo allowed Cypher execution through Graph.cypher.execute(). This facility is now instead accessible via Graph.run() and returns a lazily-evaluated Cursor rather than an eagerly-evaluated RecordList.

相同的文档显示了 Cypher.run().

的用法示例
>>> from py2neo import Graph
>>> graph = Graph(password="excalibur")
>>> graph.run("MATCH (a:Person) RETURN a.name, a.born LIMIT 4").data()
[{'a.born': 1964, 'a.name': 'Keanu Reeves'},
 {'a.born': 1967, 'a.name': 'Carrie-Anne Moss'},
 {'a.born': 1961, 'a.name': 'Laurence Fishburne'},
 {'a.born': 1960, 'a.name': 'Hugo Weaving'}]