将 py2neo 3.1.2 更新为 py2neo 4.0.0 时出现 ModuleNotFoundError

ModuleNotFoundError while updating py2neo 3.1.2 to py2neo 4.0.0

在我们的应用程序中,我们通过 py2neo 模块版本 3.1.2 连接到 Neo4j 数据库。现在我们想将它更新到 4.0.0 版本。我们已经完成了以下 link 并了解了需要进行哪些查询级别更改。

https://neo4j.com/docs/cypher-manual/current/deprecations-additions-removals-compatibility/#cypher-deprecations-additions-removals-4.0

但是,py2neo 4.0.0 版本中有几个模块不可用。请帮助我们了解是否有可用的等效模块。

from py2neo.database.status import ConstraintError
from py2neo.packages.neo4j.v1.exceptions import ProtocolError
from py2neo.packages.httpstream import http

以下是错误详情供参考。

ModuleNotFoundError: No module named 'py2neo.database.status'; 'py2neo.database' is not a package
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'py2neo.packages'

py2neo 的新版本 4 不需要 http,而是使用 bolt。我用 py2neo 中的工作版本替换了所有丢失的模块。请参阅下面的示例;

#from py2neo.database.status import ConstraintError
from py2neo  import ClientError, GraphError
#from py2neo.packages.neo4j.v1.exceptions import ProtocolError
from py2neo  import DatabaseError, TransientError, TransactionError
#from py2neo.packages.httpstream import http  <-- http is replaced by bolt connection
from py2neo import Graph

print("py2neo version: ", py2neo.__version__)
graph = Graph("bolt://localhost:7687", auth=("neo4j", "****"))
query = """<Invalid> RETURN $x as number, $x*$x as squared; """
try:
    cursor = graph.run(query, x=12)
    for record in cursor:
        print('The square of', record["number"], 'is', record["squared"])
except (ClientError, GraphError) as ex:
    print('Client Graph error: \n', ex)
except (DatabaseError, TransientError, TransactionError) as ex:
    print('DatabaseError error: \n', ex)
    
#references: https://py2neo.org/v4/index.html
#https://dzone.com/articles/introducing-bolt-neo4js-upcoming-binary-protocol-p

 RESULT:
 py2neo version:  4.2.0
 The square of 12 is 144