ImportError: cannot import name 'NodeMatcher'

Trying to import NodeMatcher using py2neo in Jupyter notebook. Used the lines below. It loads Node and Graph but not the NodeMatcher and RelationshipMatcher

import py2neo
from py2neo import Graph,  Node, Relationship, NodeMatcher, RelationshipMatcher

Getting this error:

ImportError: cannot import name 'NodeMatcher'
How can I solve this?

Both NodeMatcher and RelationshipMatcher exist in the py2neo.matching namespace in py2neo v4, and both should also be exported via py2neo as well. Therefore, your imports should work in theory.

A common cause of this problem will be a mismatch between the version of the library you think you're importing from and the actual version you are importing from. In other words, you might have an old version installed and your paths are broken. To check where you actually are, use import py2neo; py2neo.__file__.

You should also be able to see the matching module directly with an import:

>>> import py2neo
>>> py2neo.matching                                                                    
<module 'py2neo.matching' from '/home/technige/work/py2neo/py2neo/matching.py'>

You'll probably find that you have a couple of versions installed and you're pointing at the wrong one.

Note though that you shouldn't need both import py2neo and from py2neo import .... I usually just use the latter form.