0

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\ejm.py", line 1, in <module>
    from py2neo import Graph
  File "C:\Python27\lib\site-packages\py2neo-2.0a0-py2.7.egg\py2neo\__init__.py", line 27, in <module>
    from py2neo.batch import *
  File "C:\Python27\lib\site-packages\py2neo-2.0a0-py2.7.egg\py2neo\batch\__init__.py", line 19, in <module>
    from py2neo.batch.core import *
  File "C:\Python27\lib\site-packages\py2neo-2.0a0-py2.7.egg\py2neo\batch\core.py", line 24, in <module>
    from py2neo.core import NodePointer, Service
  File "C:\Python27\lib\site-packages\py2neo-2.0a0-py2.7.egg\py2neo\core.py", line 50, in <module>
    from py2neo.error.client import BindError, JoinError
ImportError: No module named error.client
user2238244
  • 229
  • 1
  • 4
  • 13

2 Answers2

3

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")

or

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

RedCraig
  • 503
  • 1
  • 4
  • 15
  • I've just reinstalled Neo4j 2.2.9 and the default directory is= C:\Program Files\Neo4j Community Tried with graph = Graph("http://neo4j:neo4j@localhost:7474") and it still gives me the same error.. – user2238244 Jun 02 '16 at 11:10
  • Well, tried with ServiceRoot too and still gives me the same error. graph = ServiceRoot("http://neo4j:1234@localhost:7474/db/data/C:/Users/htilmatine/Documents/Neo4j/default.graphdb").graph – user2238244 Jun 02 '16 at 11:25
  • I think if you're using `graph = Graph()` to connect you have to specify it with `/db/data` like: `Graph("neo4j:neo4j@localhost:7474/db/data")` – RedCraig Jun 02 '16 at 11:25
  • I don't think `ServiceRoot` expects the full directory, just try: `graph = ServiceRoot("neo4j:1234@localhost:7474")`. Is Neo4j running? Can you open it in a browser when you go to `http://localhost:7474` ? – RedCraig Jun 02 '16 at 11:27
  • What path do you refer after /db/data? I'm using the same path that indicates neo4j program when you launch it. I'm refering to the field "Database Location". – user2238244 Jun 02 '16 at 11:29
  • Ok, I executed `from py2neo import ServiceRoot` through the Python command line instead of the IDLE and it gives me the same error. So the problem is not with the graph directory.. Thanks a lot – user2238244 Jun 02 '16 at 11:36
0

I'm concerned about seeing py2neo-2.0a0 in your path name. I'd strongly recommend using a more up-to-date version of py2neo, specifically not an alpha release.

Nigel Small
  • 4,475
  • 1
  • 17
  • 15