2016-05-30 25 views
8

Sto lavorando alla migrazione manuale dei dati da postgres a Graph Database.AttributeError: l'oggetto 'Graph' non ha attributo 'cypher' nella migrazione dei dati da Postgress a Neo4j (Graph Database)

sceneggiatura che ho scritto qui di seguito:

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) 

Errore:

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

Questo problema ho risolto aggiornando py2neo alla versione 2.0.8.

pip uninstall py2neo 
pip install py2neo==2.0.8 

Sto seguendo la documentazione di py2neo.

Mentre per la produzione ancora sto ottenendo:

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

GET 404 response

Che cosa può essere problema?

risposta

8

Ho avuto anche questo problema. Nel mio caso stavo guardando la documentazione py2neo v2 ma sulla mia macchina è stato installato py2neo v3. Si dovrebbe controllare il vostro py2neo versione e sostituire .cyper ( {} interrogazione ) con .run ( {} interrogazione )

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.

0

Ho risolto il problema. Il problema era con la versione py2neo. Ho installato la versione 3 mentre la versione 2.08 è la più recente in V2.

py2neo ha consentito l'esecuzione di Cypher tramite Graph.cypher.execute().

pip uninstall py2neo 
pip install py2neo==2.0.8