使用py2neo

时间:2016-12-28 06:56:11

标签: neo4j 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','作者','内置','缓存','版权',' doc ','电子邮件','文件','许可','加载','名称','','路径','规范','版本','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 ',''数据库','弃用','deque','ext','get_auth','get_http_headers','getenv','http','整数','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?

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

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

from py2neo import Graph, Node, Relationship, authenticate

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

使用pip安装neo4j

  

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