2

I am unable to import 'neo4j' using py2neo. When I do the following;

 from py2neo import neo4j

I get the error:

  cannot import name 'neo4j' 

My py2neo version is 3.1.2

The output for the following is:

dir(py2neo)

['BoltDataSource', 'BoltNode', 'BoltPath', 'BoltRelationship', 'BoltTransaction', 'ClientError', 'Commander', 'ConstraintError', 'Cursor', 'CypherSyntaxError', 'CypherTypeError', 'CypherWriter', 'DBMS', 'DataSource', 'DatabaseError', 'Entity', 'Forbidden', 'Graph', 'GraphDatabase', 'GraphError', 'HTTPDataSource', 'HTTPResponse', 'HTTPTransaction', 'JAVA_INTEGER_MAX_VALUE', 'JAVA_INTEGER_MIN_VALUE', 'JSONResponse', 'Mapping', 'NOT_FOUND', 'Node', 'NodeSelection', 'NodeSelector', 'OrderedDict', 'PRODUCT', 'PULL_ALL', 'Path', 'PropertyDict', 'RUN', 'Record', 'Relatable', 'Relationship', 'RemoteEntity', 'ReprIO', 'Resource', 'ResourceTemplate', 'Response', 'Schema', 'ServerAddress', 'ServerAuth', 'ServerError', 'ServerPlugin', 'SetView', 'StringIO', 'Subgraph', 'ThreadLocalEntityCache', 'Transaction', 'TransactionFinished', 'TransientError', 'UNAUTHORIZED', 'URI', 'Unauthorized', 'UnmanagedExtension', 'Walkable', 'Watcher', '__author__', '__builtins__', '__cached__', '__copyright__', '__doc__', '__email__', '__file__', '__license__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'auth', 'authenticate', 'b64encode', 'basic_auth', 'bolt_hydrate', 'caching', 'cast', 'cast_node', 'cast_relationship', 'chain', 'client_errors', 'coerce_atomic_property', 'coerce_property', 'compat', 'cypher', 'cypher_escape', 'cypher_repr', 'cypher_request', 'database', 'deprecated', 'deque', 'ext', 'get_auth', 'get_http_headers', 'getenv', 'http', 'integer', 'is_collection', 'json_dumps', 'keyring', 'main', 'mktime_tz', 'normalise_request', 'order', 'packages', 'parsedate_tz', 'raise_from', 'register_server', 'relationship_case', 'remote', 'round_robin', 'selection', 'set_http_header', 'size', 'snake_case', 'status', 'stdout', 'string', 'types', 'unicode', 'update_stats_keys', 'user_agent', 'ustr', 'util', 'uuid4', 'version_tuple', 'walk', 'warn', 'watch', 'webbrowser', 'xstr']

How do I import neo4j from py2neo?

Aminah Nuraini
  • 18,120
  • 8
  • 90
  • 108
Jmj
  • 25
  • 1
  • 4

2 Answers2

1

Why do you think you can import neo4j from py2neo? Look carefully in py2neo documentation: http://py2neo.org/v3/

Your import statement should look something like from py2neo import Graph, Node, Relationship, authenticate

apc
  • 131
  • 9
  • I was trying to understand code written by a previous member of the project I am working on where neo4j has been imported from py2neo. It can also be seen here : http://codereview.stackexchange.com/questions/75842/optimizing-for-data-import-in-neo4j-using-py2neo – Jmj Dec 29 '16 at 07:41
  • It's for older version of py2neo, I think it's not even py2neo 2, maybe py2neo 1.6. You are using py2neo3. – apc Dec 30 '16 at 08:19
  • So is the "Graph" import a replacement for the "neo4j" from earlier versions? – Jmj Dec 30 '16 at 08:22
  • 1
    Not really. Read about the differences from Nigel Small himself: https://neo4j.com/blog/py2neo-2-0-unleashed/ – apc Dec 30 '16 at 08:54
  • This is exactly what I was looking for! I didn't the right place to look for it. Thank you! – Jmj Dec 30 '16 at 10:37
-1

If you want to create nodes relationship with tradtional codeing way you can create it with importing the Node, Relationship, Graph, etc from py2neo like:

from py2neo import Graph, Node, Relationship, authenticate

But if you want to execute cypher queries you need neo4j to be installed and import it on you code

install neo4j with pip

pip install neo4j

import neo4j

driver = neo4j.GraphDatabase.driver('bolt://localhost',auth=basic_auth("neo4j", "Password1"))

def get_db():
    if not hasattr(g, 'neo4j_db'):
        g.neo4j_db = driver.session()
    return g.neo4j_db

db = get_db()
results = db.run("MATCH (movie_1:Movie) "
                 "WHERE movie_1.title =~ {title} "
                 "RETURN movie", {"title": "(?i).*" + q + ".*"}