How to install neo4j for Python/Jupyter Lab?

I tried:
pip install neo4j

But it can't find the module:

from neo4j import GraphDatabase

ModuleNotFoundError: No module named 'neo4j'

Thanks, is py2neo the preferred way to interact with neo4j in Python?

pip install neo4j working for me. Check if pip has completed without any error and package is available in site-packages.

import sys
sys.path

and py2neo is community driver

Thanks, the import works fine just using python, but it can't find the package in Jupyter Lab.

I've got the import to work in Jupyter Lab by installing jupyterlab in the same conda environment.

The documentation is not clear what to do next, e.g., how to connect to a database, how to create a new database using Cypher. Where can I find good examples?

Great..
Some examples: https://github.com/neo4j-examples/movies-python-bolt
https://github.com/neo4j/neo4j-python-driver
https://nicolewhite.github.io/neo4j-jupyter/hello-world.html
and Manual: https://neo4j.com/docs/driver-manual/1.7/
https://neo4j.com/docs/api/python-driver/1.7/#

  1. Launch anconda (i use this) and launch notebook
  2. Launch Neo4j Desktop and start a database you want to connect to.
  3. IN the Jupyter notebook. (basically installs py2neo into your environment)
    Type our the following in separate lines to first install py2neo, then import the library and finally use the features. How to use the full features of py2neo is available in the py2neo documentation above.
pip install py2neo
from py2neo import Graph
graph = Graph("bolt://localhost:7687", auth=("neo4j", "asdfgh123"))
uery = "MATCH (n) return n"
graph.run(query).data()

This would be the simplest way to connect and retrieve results. Add on queries to run to perform additional steps on your data.

Thanks, that does it! :+1:

The examples I found online just did:
graph = Graph()

and that obviously didn't work.

1 Like

glad that i could of help :slight_smile: