Jedi stopped working after upgrading Linux

I recently made a clean install of Debian 10 (Buster). I migrated my emacs.d and .emacs hoping that everything will work as usual. I didn’t have much trouble with Emacs except for Jedi Server, which is responsible for Python auto-completion, has stopped working. It took me some time to fix this problem, and I am posting the fix hoping it will save someone else’s time.

Error Message

I tried to reinstall Jedi, the package installs fine, but when I tried jedi:install-server I got this error:

Running: pip install --upgrade /home/****/.emacs.d/elpa/jedi-core-20191011.1750/...Done
deferred error : (error "Deferred process exited abnormally:
  command: /home/****/.emacs.d/.python-environments/default/bin/pip
  exit status: exit 1
  event: exited abnormally with code 1
  buffer contents: \"Traceback (most recent call last):
  File \\\"/home/****/.emacs.d/.python-environments/default/bin/pip\\\", line 7, in 
    from pip import main
  File \\\"/home/****/.emacs.d/.python-environments/default/local/lib/python2.7/site-packages/pip/\\\", line 72, in 
    from pip.log import logger
  File \\\"/home/****/.emacs.d/.python-environments/default/local/lib/python2.7/site-packages/pip/\\\", line 6, in 
    import logging
  File \\\"/usr/lib/python2.7/logging/\\\", line 26, in 
    import sys, os, time, cStringIO, traceback, warnings, weakref, collections
  File \\\"/usr/lib/python2.7/\\\", line 14, in 
    from _weakref import (
ImportError: cannot import name _remove_dead_weakref


After googling around, I found my solution. I needed to install virtualenv as it is required by Jedi, and also fixing the python environment in .emacs.d.

You can install virtualenv using the package manager:

sudo apt install virtualenv

Then apply this command replacing [USER] with your home directory:

virtualenv --system-site-packages /home/[USER]/.emacs.d/.python-environments/default

This should fix your problem!

To understand what the last command does, you can check the man page:

           Give access to the global site-packages modules to the virtual environment.

It seems like the Python environment created in .emacs.d didn’t have access to the site-packages modules, and this command fixed it.

Hope this fix saved your time!

comments powered by Disqus