繁体   English   中英

使用 py2neo 导入 neo4j

[英]Importing neo4j with py2neo

我无法使用 py2neo 导入“neo4j”。 当我执行以下操作时;

 from py2neo import neo4j

我收到错误:

  cannot import name 'neo4j' 

我的 py2neo 版本是 3.1.2

以下输出为:

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']

如何从 py2neo 导入 neo4j?

为什么你认为你可以从 py2neo 导入 neo4j? 仔细查看 py2neo 文档: http ://py2neo.org/v3/

您的导入语句应该类似于from py2neo import Graph, Node, Relationship, authenticate

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

from py2neo import Graph, Node, Relationship, authenticate

但是如果你想执行密码查询,你需要安装neo4j并将其导入你的代码

用pip安装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