py2neo: 没有名为 core 的模块

py2neo: no module named core

我正在尝试使用 python 将一些文件上传到 Neo4j 数据库中。

我正在使用 Python 2.7.6 并且已经成功安装了 neo4j-driver 和 py2neo 模块:

$ sudo pip install neo4j-driver
Downloading/unpacking neo4j-driver
  Downloading neo4j-driver-1.3.1.tar.gz (167kB): 167kB downloaded
  Running setup.py (path:/tmp/pip_build_root/neo4j-driver/setup.py) egg_info for package neo4j-driver

    warning: no previously-included files matching '*.class' found anywhere in distribution
    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    warning: no previously-included files matching '*.pyo' found anywhere in distribution
    warning: no previously-included files matching '*.so' found anywhere in distribution
    warning: no previously-included files matching '*.dll' found anywhere in distribution
    warning: no previously-included files matching '__pycache__' found anywhere in distribution
    no previously-included directories found matching 'test'
Installing collected packages: neo4j-driver
  Running setup.py install for neo4j-driver
    building 'neo4j.bolt._io' extension
    x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c neo4j/bolt/_io.c -o build/temp.linux-x86_64-2.7/neo4j/bolt/_io.o
    x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/neo4j/bolt/_io.o -o build/lib.linux-x86_64-2.7/neo4j/bolt/_io.so
    building 'neo4j.packstream._packer' extension
    x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c neo4j/packstream/_packer.c -o build/temp.linux-x86_64-2.7/neo4j/packstream/_packer.o
    x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/neo4j/packstream/_packer.o -o build/lib.linux-x86_64-2.7/neo4j/packstream/_packer.so
    building 'neo4j.packstream._unpacker' extension
    x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c neo4j/packstream/_unpacker.c -o build/temp.linux-x86_64-2.7/neo4j/packstream/_unpacker.o
    x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/neo4j/packstream/_unpacker.o -o build/lib.linux-x86_64-2.7/neo4j/packstream/_unpacker.so

    warning: no previously-included files matching '*.class' found anywhere in distribution
    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    warning: no previously-included files matching '*.pyo' found anywhere in distribution
    warning: no previously-included files matching '*.so' found anywhere in distribution
    warning: no previously-included files matching '*.dll' found anywhere in distribution
    warning: no previously-included files matching '__pycache__' found anywhere in distribution
    no previously-included directories found matching 'test'
  Could not find .egg-info directory in install record for neo4j-driver
Successfully installed neo4j-driver
Cleaning up...






$ sudo pip install py2neo
Downloading/unpacking py2neo
  Downloading py2neo-3.1.2.tar.gz (100kB): 100kB downloaded
  Running setup.py (path:/tmp/pip_build_root/py2neo/setup.py) egg_info for package py2neo

    warning: no previously-included files found matching 'CONTRIBUTING.md'
    warning: no previously-included files found matching 'README.md'
    warning: no previously-included files matching '*' found under directory 'test'
    warning: no previously-included files matching '*' found under directory 'test_ext'
Installing collected packages: py2neo
  Running setup.py install for py2neo

    warning: no previously-included files found matching 'CONTRIBUTING.md'
    warning: no previously-included files found matching 'README.md'
    warning: no previously-included files matching '*' found under directory 'test'
    warning: no previously-included files matching '*' found under directory 'test_ext'
    Installing neokit script to /usr/local/bin
    Installing geoff script to /usr/local/bin
    Installing py2neo script to /usr/local/bin
  Could not find .egg-info directory in install record for py2neo
Successfully installed py2neo
Cleaning up...

但有人抱怨没有名为 core

的模块
$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from py2neo.core import Graph
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named core
>>> 

还有其他人遇到过这个问题吗?

py2neo docs 说你应该使用:

from py2neo import Graph

而不是:

from py2neo.core import Graph

即:去掉上面代码行中的.core。看看 this link.

您安装了 Neo4j 的官方 Python 驱动程序。 (永远不要使用 sudo 安装,使用虚拟环境。)

sudo pip install neo4j-driver

然后吐槽py2neo

...

from py2neo import Graph

官方 Python Neo4j 驱动程序 4.0 的 API 文档:

https://neo4j.com/docs/api/python-driver/4.0/