ModuleNotFoundError while updating py2neo 3.1.2 to py2neo 4.0.0

Viewed 195

In our application, we are connecting to Neo4j database through py2neo module version 3.1.2. Now we would like to update it to 4.0.0 version. We have gone through the below link and understood what are the query level changes required.

https://neo4j.com/docs/cypher-manual/current/deprecations-additions-removals-compatibility/#cypher-deprecations-additions-removals-4.0

However, there are few modules not available in py2neo 4.0.0 version. Please help us to understand if there is any equivalent module available.

from py2neo.database.status import ConstraintError
from py2neo.packages.neo4j.v1.exceptions import ProtocolError
from py2neo.packages.httpstream import http

Below are the error details for the reference.

ModuleNotFoundError: No module named 'py2neo.database.status'; 'py2neo.database' is not a package
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'py2neo.packages'
1 Answers

The new version 4 of py2neo is NOT requiring http but instead using bolt. I replaced all your missing modules with a working version in py2neo. See my example below;

#from py2neo.database.status import ConstraintError
from py2neo  import ClientError, GraphError
#from py2neo.packages.neo4j.v1.exceptions import ProtocolError
from py2neo  import DatabaseError, TransientError, TransactionError
#from py2neo.packages.httpstream import http  <-- http is replaced by bolt connection
from py2neo import Graph

print("py2neo version: ", py2neo.__version__)
graph = Graph("bolt://localhost:7687", auth=("neo4j", "****"))
query = """<Invalid> RETURN $x as number, $x*$x as squared; """
try:
    cursor = graph.run(query, x=12)
    for record in cursor:
        print('The square of', record["number"], 'is', record["squared"])
except (ClientError, GraphError) as ex:
    print('Client Graph error: \n', ex)
except (DatabaseError, TransientError, TransactionError) as ex:
    print('DatabaseError error: \n', ex)
    
#references: https://py2neo.org/v4/index.html
#https://dzone.com/articles/introducing-bolt-neo4js-upcoming-binary-protocol-p

 RESULT:
 py2neo version:  4.2.0
 The square of 12 is 144
Related