gpt4 book ai didi

python - 属性错误 : 'Graph' object has no attribute 'cypher' in migration of data from Postgress to Neo4j(Graph Database)

转载 作者:太空狗 更新时间:2023-10-29 20:10:41 25 4
gpt4 key购买 nike

我正在手动将数据从 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 v2文档,但在我的机器上安装了 py2neo v3 .您应该检查您的 py2neo 版本并将 .cyper({query}) 替换为 .run({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.

关于python - 属性错误 : 'Graph' object has no attribute 'cypher' in migration of data from Postgress to Neo4j(Graph Database),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37530309/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com