Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am working on migration of data from postgres to Graph Database manually.

I have wrote script below:

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)

Error:

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

This issue I resolved by updating py2neo to version 2.0.8.

pip uninstall py2neo
pip install py2neo==2.0.8

I am following documentation of py2neo.

While for production I am still getting:

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

GET 404 response

What can be issue?

like image 431
Usman Maqbool Avatar asked May 30 '16 16:05

Usman Maqbool


2 Answers

I had this problem too. In my case I was looking at the py2neo v2 documentation but on my machine was installed py2neo v3. You should check your py2neo version and replace .cyper({query}) with .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.

like image 51
Lucian Oprea Avatar answered Sep 19 '22 11:09

Lucian Oprea


I have resolved issue. Issue was with version of py2neo. I have installed version 3 while version 2.08 is latest in V2.

py2neo allowed Cypher execution through Graph.cypher.execute().

pip uninstall py2neo
pip install py2neo==2.0.8
like image 44
Usman Maqbool Avatar answered Sep 22 '22 11:09

Usman Maqbool