cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

ModuleNotFoundError: No module named 'py2neo.cypher.error'

Hello everyone.

I'm trying to handle the Constraint Validation exceptions into my Python code.
However I'm facing ModuleNotFoundError: No module named 'py2neo.cypher.error' error even after install py2neo==4.1.3.

My code:
from py2neo import Graph
from py2neo.cypher.error.schema import ConstraintViolation
import traceback
...
...
try:
...
...
except ConstraintViolation as e:
print(traceback.format_exc())
...
...

Does anyone already faced this?
How can I solve that?

Many thanks.

1 REPLY 1

This code snipped seems to be written for an older version of py2neo. I'm not an export for py2neo but I think the current approach to this goes something along those lines:

from py2neo import Neo4jError

try:
    ...
except Neo4jError as e:
    if e.code == "Neo.ClientError.Schema.ConstraintViolation":
        ....
    else:
        raise

Haven't tested it. So maybe it needs some slight adjustment.

Those links might be helpful:

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online