Python 3.6.8 – Jedi – ImportError: cannot import name 'traverse_parents'

Question:

<TL;DR>

When running import jedi in python 3.6.8 I get the following import error (see end of post for full traceback):

...
from jedi.common import traverse_parents
ImportError: cannot import name 'traverse_parents'

</TL;DR>

I checked in ~/.local/lib/python3.6/site-packages/jedi/common.py : There’s a function called traverse_parents alright so there’s definitely some witchery at work. Not the first time I’ve run into one of those "undefined name" problems, but I’m running out of ideas on this one.

Already tried :

  • uninstalling, reinstalling, upgrading the "jedi" package for pip3
  • pretty much the same jazz for a couple other packages with "jedi" in their names
  • upgrading pip3 to 20.2.1 and redoing the same reinstalling routine
  • installing jedi for python2 because why not (hey, it works fine in python2 but who cares)
  • also tried installing python-jedi from apt-get (I removed it afterwards)
  • incantations to ancient Babylonian demons (to no avail, they don’t work Sundays)

Vague clues on how I might fix it :

  • getting the latest version of jedi from github and somehow installing it without making a mess (fat chance)
  • uninstalling jedi and reinstalling it from within Neovim (hey that might achieve the previous point)

I’ve scoured the web for the answer to this problem but I’m getting nowhere. Has anyone experienced something similar and managed to solve it ?

Any suggestion welcome.


The full traceback :

Error detected while processing function provider#python3#Call:
line   18:                                                                                                                             
Error invoking 'python_execute' on channel 5 (python3-script-host):
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/vee/.local/lib/python3.6/site-packages/jedi/__init__.py", line 32, in <module>
    from jedi.api import Script, Interpreter, set_debug_funcion, 
  File "/home/vee/.local/lib/python3.6/site-packages/jedi/api/__init__.py", line 24, in <module>
    from jedi.api import classes
  File "/home/vee/.local/lib/python3.6/site-packages/jedi/api/classes.py", line 26, in <module>
    from jedi.inference import imports
  File "/home/vee/.local/lib/python3.6/site-packages/jedi/inference/__init__.py", line 70, in <module>
    from jedi.inference import imports
  File "/home/vee/.local/lib/python3.6/site-packages/jedi/inference/imports.py", line 24, in <module>
    from jedi.inference import sys_path
  File "/home/vee/.local/lib/python3.6/site-packages/jedi/inference/sys_path.py", line 8, in <module>
    from jedi.common import traverse_parents
ImportError: cannot import name 'traverse_parents'
Asked By: jwav

||

Answers:

Fixed it :
I reinstalled the latest version of jedi via pip with this command :

pip3 install -e git://github.com/davidhalter/jedi.git#egg=jedi

Now, the command import jedi doesn’t generate any exception and it seems to work alright in Neovim.

The reason why the default version installed with pip3 install jedi generated that ImportError is beyond what I can guess. Maybe this version was faulty itself, maybe some quirk of my python environment…

Edit: According to David Halter in the comment below, it seems to be a pip bug

Anyway. If you have the same problem, try this fix.

Answered By: jwav