ImportError: cannot import name 'GraphDatabase' from 'neo4j'

Hi everyone.

I'm on Mac OS X 10.15.4

I'm attempting to connect to my graph database using the python driver. I'm using Python 3.7.7 in a virtual environment with the following packages installed with pip.

Pip freeze output:

cycler==0.10.0
decorator==4.4.2
graphrole==1.0.0
kiwisolver==1.2.0
matplotlib==3.2.1
neo4j==1.7.6
neo4j-driver==1.7.6
neobolt==1.7.17
neotime==1.7.4
networkx==2.2
numpy==1.15.3
pandas==0.23.4
pprint==0.1
pyparsing==2.4.7
python-dateutil==2.8.1
pytz==2019.3
scikit-learn==0.20.2
scipy==1.1.0
seaborn==0.10.0
six==1.14.0

Neo4j version 3.5.14, Desktop verision 1.2.7.

Drivers were installed using pip.

As you can see it works from the python shell but not when running a .py file that imports it. It's also inconsistent when importing in the shell as many times I would get the same error. I've tried both neo4j and neo4j-driver separately and together and neither has worked.

Any suggestions?

Update:

I've also downloaded the drivers and installed them with

python setup.py install

Script still won't work, but it works from the shell.

You have to rename the file, because from neo4j import GraphDatabase tries to find in the local file first and not in the package, hence this error.

1 Like

Sorry, I don't understand your reply. Which file to rename?

Hi Edcherednik,

Can you check if there is a file in your python project named 'neo4j.py'?
If so, that's the one you need to rename.

1 Like