我无法使用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','作者','内置','
如何从py2neo导入neo4j?
答案 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 + ".*"}