AttributeError: 'Graph' object has no attribute 'cypher' in migration of data from Postgress to Neo4j(Graph Database)

AttributeError: 'Graph' object has no attribute 'cypher' in migration of data from Postgress to Neo4j(Graph Database)

我正在手动将数据从 postgres 迁移到图形数据库。

我写了下面的脚本:

import psycopg2
from py2neo import authenticate, Graph

authenticate("localhost:7474", "neo4j", "password")
n4j_graph = Graph("http://localhost:7474/db/data/")


try:
    conn=psycopg2.connect("dbname='db_name' user='user' password='password'")
except:
    print "good bye"

cur = conn.cursor()
try:
    cur.execute("""SELECT * from table_name""")
except:
    print "not found"
rows = cur.fetchall()


for row in rows:
    username = row[4]
    email = row[7]
    s = '''MERGE (u:User { username: "%(username)s"}) MERGE (e:Email { email: "%(email)s"}) CREATE UNIQUE (u)-[:BELONGS_TO]->(e)''' %{"username": username, "email": email}
    print s
    n4j_graph.cypher.execute(s)

错误:

AttributeError: 'Graph' object has no attribute 'cypher'

我通过将 py2neo 更新到版本 2.0.8 解决了这个问题。

pip uninstall py2neo
pip install py2neo==2.0.8

我正在关注 py2neo 的文档。

虽然在生产中我仍然得到:

AttributeError: 'Graph' object has no attribute 'cypher'

GET 404 response

有什么问题?

我已经解决了问题。 问题出在 py2neo 的版本上。我已经安装了版本 3,而版本 2.08 是最新的 V2。

py2neo 允许通过 Graph.cypher.execute().

执行 Cypher
pip uninstall py2neo
pip install py2neo==2.0.8

我也有这个问题。在我的例子中,我正在查看 py2neo v2 documentation but on my machine was installed py2neo v3。您应该检查 py2neo 版本并将 .cyper({query}) 替换为 .运行({查询})

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.