Py2neo ImportError: cannot import name 'import_best'


(David Chang) #1

Hello,

The code throwing the error looks like this:

from py2neo import Graph
graph = Graph()
###same if I do "graph = Graph("bolt://localhost:7687", auth=("neo4j", "0000"))"
And I get this:

Traceback (most recent call last):
File "/Users/dchang/anaconda3/envs/dec2018/lib/python3.6/site-packages/py2neo/database.py", line 88, in new
inst = cls._instances[key]
KeyError: '0398321414780170895a995e32ce7977'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/dchang/anaconda3/envs/dec2018/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 3267, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
graph = Graph()
File "/Users/dchang/anaconda3/envs/dec2018/lib/python3.6/site-packages/py2neo/database.py", line 305, in new
database = Database(uri, **settings)
File "/Users/dchang/anaconda3/envs/dec2018/lib/python3.6/site-packages/py2neo/database.py", line 92, in new
from py2neo.internal.http import HTTPDriver, HTTPSDriver
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/Users/dchang/anaconda3/envs/dec2018/lib/python3.6/site-packages/py2neo/internal/http.py", line 29, in
from neo4j.v1 import Driver, Session, StatementResult, TransactionError, SessionError
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/Users/dchang/anaconda3/envs/dec2018/lib/python3.6/site-packages/neo4j/v1/ init .py", line 22, in
from .bolt import *
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/Users/dchang/anaconda3/envs/dec2018/lib/python3.6/site-packages/neo4j/v1/bolt.py", line 32, in
from .types import Record
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/Users/dchang/anaconda3/envs/dec2018/lib/python3.6/site-packages/neo4j/v1/types/ init .py", line 33, in
from neo4j.packstream import Structure
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "/Users/dchang/anaconda3/envs/dec2018/lib/python3.6/site-packages/neo4j/packstream/ init .py", line 22, in
from neo4j.util import import_best as _import_best
ImportError: cannot import name 'import_best'

It was working perfectly fine just a couple of days ago, and something must have changed, but I have no idea why this is happening.

It happens with both neo4j 3.4 and 3.5, and I'm using py2neo 4.1.3

I would appreciate any help!


(David Chang) #2

I've fixed it!
Like for a lot of problems having to do with import errors, there was a problem with compatibility between py2neo and the official neo4j driver.

The exact versions you need currently are:
neo4j-driver 1.6.2
neotime 1.0.0
py2neo 4.1.3

Based on what I've tried, it seems like you must have neo4j-driver==1.6.2 (not 1.7), and you also must not have neo4j==1.7.1, which is kind of concerning because the official driver documentation says:

"Note The driver is currently released under two package names on PyPI: neo4j and neo4j-driver. Installing from neo4j is recommended since neo4j-driver will be removed in a future release."

That sort of sounds like the version that works will be removed in the future. My guess is py2neo will have to be updated to match that at some point.

**this post is identical to the github issue I just opened and closed for py2neo, but thought it might be useful to leave it here as well