简体   繁体   English

使用 py2neo 导入 neo4j

[英]Importing neo4j with py2neo

I am unable to import 'neo4j' using py2neo.我无法使用 py2neo 导入“neo4j”。 When I do the following;当我执行以下操作时;

 from py2neo import neo4j

I get the error:我收到错误:

  cannot import name 'neo4j' 

My py2neo version is 3.1.2我的 py2neo 版本是 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?如何从 py2neo 导入 neo4j?

Why do you think you can import neo4j from py2neo?为什么你认为你可以从 py2neo 导入 neo4j? Look carefully in py2neo documentation: http://py2neo.org/v3/仔细查看 py2neo 文档: http ://py2neo.org/v3/

Your import statement should look something like from py2neo import Graph, Node, Relationship, authenticate您的导入语句应该类似于from py2neo import Graph, Node, Relationship, authenticate

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:如果要使用传统编码方式创建节点关系,可以通过从 py2neo 导入节点、关系、图形等来创建它,例如:

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但是如果你想执行密码查询,你需要安装neo4j并将其导入你的代码

install neo4j with pip用pip安装neo4j

pip install neo4j点安装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 + ".*"}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM