【问题标题】:Instance of 'Graph' has no 'cypher' member - python'Graph' 的实例没有'cypher' 成员 - python
【发布时间】:2020-03-06 14:33:28
【问题描述】:

我正在尝试使用 Py2neo 连接到 Neo4j 实例

from py2neo import Graph
import re, string

# default uri for local Neo4j instance
graphdb = Graph('http://neo4j:neo4j@localhost:7474/db/data')

# parameterized Cypher query for data insertion
# t is a query parameter. a list with two elements: [word1, word2]
INSERT_QUERY = '''
    FOREACH (t IN {wordPairs} |
        MERGE (w0:Word {word: t[0]})
        MERGE (w1:Word {word: t[1]})
        CREATE (w0)-[:NEXT_WORD]->(w1)
        )
'''

并加载数据,然后对加载的数据应用一些密码命令

# load our text corpus into Neo4j
def loadFile():

    tx = graphdb.cypher.begin()
    with open('data/ceeaus.dat', encoding='ISO-8859-1') as f:
        count = 0
        for l in f:
            params = {'wordPairs': arrifySentence(l)}
            tx.append(INSERT_QUERY, params)
            tx.process()
            count += 1
            # process in batches of 100 insertion queries
            if count > 100:
                tx.commit()
                tx = graphdb.cypher.begin()
                count = 0
    f.close()
    tx.commit()

现在,问题是 vscode 不将 cypher 识别为 Graph 的成员,或者不将 graphdb 识别为 Graph em>图表实例。

问题出在这一行graphdb.cypher.begin() 我尝试阅读docs for cypher 并发现Graph 类中存在Cypher 成员;以及 py2neo 密码中的 begin 函数。

我正在使用 py2neo v 4.3 和 python 3.7 和 neo4j v 1.2.4 提前致谢。

【问题讨论】:

    标签: neo4j graphql python-3.7


    【解决方案1】:

    由于您使用的是py2neo 4.3,因此您需要使用 v4 API。您正在查看 v2 文档。

    在 py2neo v4 中,Graph 没有 cypher 方法。相反,您可能想要使用run 方法。

    【讨论】:

      猜你喜欢
      • 2020-05-05
      • 2019-05-27
      • 2020-12-04
      • 1970-01-01
      • 2018-11-29
      • 2021-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多