cancel
Showing results for 
Search instead for 
Did you mean: 

Py2neo ImportError: cannot import name 'import_best'

david_chang
Node Link

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!

4 REPLIES 4

david_chang
Node Link

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

technige
Neo4j
Neo4j

The dependencies have been updated in py2neo 4.2.

Hi, I am trying to run an example of Using Neo4j from Python - Developer Guides using py2neo, so the code is:

from py2neo import Graph
graph = Graph()

tx = graph.begin()
for name in ["Alice", "Bob", "Carol"]:
    tx.append("CREATE (person:Person name: $name) RETURN person", name=name)
alice, bob, carol = [result.one for result in tx.commit()]

I have installed py2neo with pip install py2neo, I am using Windows, but when I run the code, I got:

ImportError: cannot import name 'Graph' from partially initialized module 'py2neo' (most likely due to a circular import)

It seems that doesnt recognize Graph from py2neo, any suggestion about how I can solve it for Windows?

Note: If I run in the console:
from py2neo import Graph
graph = Graph()
graph returns:
Graph('bolt://neo4j@localhost:7687')

But in the .py file the code doesn't work

Actually I was having the problem of Graph with pycharm, I opened it with Visual Studio Code and the ImportError of Graph is gone, but I have the problem of append, it shows:

  • tx.append("CREATE (person:Person name: $name) RETURN person", name=name)AttributeError: 'Transaction' object has no attribute 'append'*

and it happens not only in Windows, even in Mac, and linux

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.