Emacs: `jedi:install-server` fails even though `virtualenv` is installed

Viewed 692

I am trying to install JEDI autocompletion for Emacs according to this manual.

When I enter M-x jedi:install-server, I get the error Program named "virtualenv" does not exist. I followed the advice in this answer and installed it using pip install virtualenv. Now when I enter virtualenv in the terminal, I get this output:

usage: virtualenv [--version] [--with-traceback] [-v | -q] [--app-data APP_DATA] [--clear-app-data] [--discovery {builtin}] [-p py] [--creator {builtin,cpython3-posix,venv}] [--seeder {app-data,pip}] [--no-seed]
                  [--activators comma_sep_list] [--clear] [--system-site-packages] [--symlinks | --copies] [--download | --no-download] [--extra-search-dir d [d ...]] [--pip version] [--setuptools version] [--wheel version] [--no-pip]
                  [--no-setuptools] [--no-wheel] [--symlink-app-data] [--prompt prompt] [-h]
                  dest
virtualenv: error: the following arguments are required: dest

Then I restarted, entered M-x jedi:install-server, but I still get the same error.

I am using GNU Emacs 26.3 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.30) of 2019-12-03 on Linux Mint 19.3 Tricia.

How can I fix this the error and start using JEDI autocompletion?

Update 1: Also, whenever I open a Python file, I get this warning

*** EPC Server Config ***
Server arguments: ("/usr/bin/python" "/home/XXXXXXX/.emacs.d/elpa/jedi-core-20191011.1750/jediepcserver.py")
Actual command: /usr/bin/python
VIRTUAL_ENV envvar: nil

*** jedi-mode is disabled in #<buffer createPageStructure.py> ***
Fix the problem and re-enable it.

*** You may need to run "M-x jedi:install-server". ***
This could solve the problem especially if you haven't run the command yet
since Jedi.el installation or update and if the server complains about
Python module imports.
3 Answers

I have a similar problem, I'm also using Linux Mint Tricia. I want to use company-jedi instead of jedi-ac

In my case, I wanted jedi, and emacs to use python3.8. So I want jedi virtualenv based on python3.8.

Jedi virtualenv is created by using emacs-python-enviroment package.

My problem seems to come from the fact that emacs-python-enviroment uses the option '--system-site-package' by default, so I've got plenty of errors since the system python3 is python3.6 and I don't (and I don't want to) have every needed package installed in system wide python3.

I solved the problem adding option '--no-site-package' (see this) to emacs-python-enviroment

emacs-python-enviroment is used to create the jedi virtualenv, named 'default' and located in `~/.emacs.d/.python-enviroments/' you can configure a different name and location of this virtualenv if you want (for more info see this)

This is my working configuration. You can specify a different python instead of python3.8 (the one I use)

 (setq python-shell-interpreter "/usr/bin/python3.8")
 (setq py-python-command "/usr/bin/python3.8")        ; maybe not needed
 (setq python-python-command "/usr/bin/python3.8")    ; maybe not needed

 (use-package company-jedi             ;;; company-mode completion back-end for Python JEDI
   :ensure t
   :config
   (setq jedi:environment-virtualenv
         (append python-environment-virtualenv
                 '("--no-site-packages" "--python" "/usr/bin/python3.8")))
   ;;(setq jedi:environment-virtualenv (list (expand-file-name "~/.emacs.d/.python-environments/")))
   (add-hook 'python-mode-hook 'jedi:setup)
   (setq jedi:complete-on-dot t)
   (setq jedi:use-shortcuts t)
   (defun config/enable-company-jedi ()
     (add-to-list 'company-backends 'company-jedi))
   (add-hook 'python-mode-hook 'config/enable-company-jedi)
   )

I no longer use jedi and have switched to lsp-mode, but below is my old working config using company-jedi for Python completion. When python-mode is being loaded, it will call jedi:install-server-block to install jedi support if it has not been installed. You may want to check the *Messages* buffer to see if it prints out Installing jedi server.... Hope this could help.

(use-package company-jedi
  :if (executable-find "virtualenv")
  :ensure t
  :bind
  (:map python-mode-map
        ("M-." . jedi:goto-definition)
        ("M-," . jedi:goto-definition-pop-marker))
  :config
  (unless (file-exists-p
           (expand-file-name
            ".python-environments" user-emacs-directory))
    (message "Installing jedi server...")
    (jedi:install-server-block)
    (message "Installing jedi server...done"))
  :hook
  (python-mode
   . (lambda ()
       (setq-local company-backends
                   (append (list 'company-jedi) company-backends)))))

Add the 'server arguments' shown above in the warning to the .emacs file this way.

(setq jedi:server-command ("/usr/bin/python" "/home/XXXXXXX/.emacs.d/elpa/jedi-core-20191011.1750/jediepcserver.py"))
Related