在Docker中连接neo4j时出现py2neo AddressError

时间:2018-08-22 18:38:33

标签: docker neo4j py2neo

使用py2neo 4.10和Python 3.7.0在Neo4j 3.4.6上创建Graph对象时遇到困难。

我创建了一个运行Neo4j的Docker容器,并使用Dockerfile条目ENV NEO4J_AUTH=none禁用了身份验证。我确认可以使用http://localhost:7474从主机浏览到Neo4j数据库,并且不需要输入密码。

我为我的Web服务器创建了第二个Docker容器。我使用Docker exec -it 033f92b042c1 /bin/bash访问了Bash shell。我确认可以对包含Neo4j安装的Docker映像执行ping操作。

在第二个Docker映像中,我尝试创建一个Database对象或一个Graph对象。

import neo4j
import py2neo
from py2neo import Graph
graph = Graph("bolt://172.17.0.3:7687")

我尝试了不同的协议和localhost而不是IP。在每种情况下,Python都会抛出以下内容:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/py2neo/database.py", line 88, in __new__
    inst = cls._instances[key]
KeyError: '5280a6d494b601f0256493eab3a08e55'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/py2neo/database.py", line 305, in __new__
    database = Database(uri, **settings)
  File "/usr/local/lib/python3.7/site-packages/py2neo/database.py", line 92, in __new__
    from py2neo.internal.http import HTTPDriver, HTTPSDriver
  File "/usr/local/lib/python3.7/site-packages/py2neo/internal/http.py", line 26, in <module>
    from neo4j.addressing import SocketAddress
  File "/usr/local/lib/python3.7/site-packages/neo4j/addressing.py", line 26, in <module>
    from neo4j.exceptions import AddressError
ImportError: cannot import name 'AddressError' from 'neo4j.exceptions' (/usr/local/lib/python3.7/site-packages/neo4j/exceptions.py)

我是否缺少依赖项,或者我应该以其他方式连接Docker映像吗?

1 个答案:

答案 0 :(得分:2)

Py2neo不需要neo4j。原因可能是neo4j正在产生问题。 就我而言,请确保干净安装,我删除了所有与neo4j相关的模块,然后安装py2neo及其要求的neo4j-driver。

pip uninstall neo4j neobolt neo4restclient neo4j-driver py2neo

然后安装:
pip install neo4j-driver py2neo

我希望那行得通。