user2238244 user2238244 - 1 year ago 153
Python Question

Error connecting py2neo

I'm trying to connect my neo4J DB with Python using py2neo.

I'm following the example extracted from py2neo 2 API but there's no way to get it work.

My code:

from py2neo import Graph
graph = Graph("http://neo4j:1234@localhost:7474/C:/Users/htilmatine/Documents/Neo4j/default.graphdb")

The error:

Traceback (most recent call last):
File "D:\TFG\python\", line 1, in <module>
from py2neo import Graph
File "C:\Python27\lib\site-packages\py2neo-2.0a0-py2.7.egg\py2neo\", line 27, in <module>
from py2neo.batch import *
File "C:\Python27\lib\site-packages\py2neo-2.0a0-py2.7.egg\py2neo\batch\", line 19, in <module>
from py2neo.batch.core import *
File "C:\Python27\lib\site-packages\py2neo-2.0a0-py2.7.egg\py2neo\batch\", line 24, in <module>
from py2neo.core import NodePointer, Service
File "C:\Python27\lib\site-packages\py2neo-2.0a0-py2.7.egg\py2neo\", line 50, in <module>
from py2neo.error.client import BindError, JoinError
ImportError: No module named error.client

Answer Source

The connection docs are here.

If you're just using a default install and default graph data directory, you should be able to connect with:

graph = Graph("http://neo4j:1234@localhost:7474/db/data")


from py2neo import ServiceRoot
graph = ServiceRoot("http://neo4j:1234@localhost:7474").graph

If you're not using the default data directory then

  • it needs to be a subdirectory of /neo4j/data
  • you need to provide a relative path to it from the neo4j directory in your uri like:

    graph = Graph("http://neo4j:1234@localhost:7474/db/data/my_graph_dir")

EDIT: fixed the first Graph url, and added how to connect with ServiceRoot

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download