emacsorphanage / company-jedi

Company backend for Python jedi
101 stars 12 forks source link

Error using company-jedi #18

Closed jwintz closed 7 years ago

jwintz commented 7 years ago

Here is my setup:

(prolusion-require-package 'company-jedi)

;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Completion configuration
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(autoload 'jedi:setup "jedi" nil t)

(add-hook 'python-mode-hook 'jedi:setup)

(setq jedi:environment-root prolusion-jedi-dir)
(setq python-environment-directory prolusion-jedi-dir)
(setq python-environment-default-root-name "root")
(setq jedi:complete-on-dot t)

;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Completion setup
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(eval-after-load 'company '(add-to-list 'company-backends 'company-jedi))

;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Completion hooks
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(add-hook     'python-mode-hook 'company-mode)

However I got the following errors:

Error (jedi): Failed to start Jedi EPC server.
*** 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.

And:

File \"/Users/jwintz/.emacs.d/prolusion-elpa/jedi-core-20160709.722/jediepcserver.py\", line 228, in jedi_epc_server
    import_jedi()
  File \"/Users/jwintz/.emacs.d/prolusion-elpa/jedi-core-20160709.722/jediepcserver.py\", line 274, in import_jedi
    import jedi
ImportError: No module named jedi
")

However, I have run M-x jedi:install-server multiple times.

Any hints ? I got it working for some seconds but still I have many machines I wanted to have a generic solution.

Cheers,

jwintz commented 7 years ago

The point is I can't find a jedi.py in my elpa directory that is configured to be:

(setq package-user-dir prolusion-elpa-dir)

where:

(defvar prolusion-dir          (file-name-directory load-file-name))
(defvar prolusion-elpa-dir     (expand-file-name "prolusion-elpa"     prolusion-dir) "")
syohex commented 7 years ago

Could you show us output of M-x jedi:show-version-info ? If all dependencies are installed correctly, it shows as below.

(:emacs-version "25.1.1" :jedi-version "0.2.7")
((:version "2.7.10 (default, Oct 23 2015, 19:19:21) \n[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)]" :name "sys" :file nil)
 (:version "0.9.0" :name "jedi" :file "/Users/shohei.yoshida/.emacs.d/.python-environments/default/lib/python2.7/site-packages/jedi/__init__.pyc")
 (:version "0.0.5" :name "epc" :file "/Users/shohei.yoshida/.emacs.d/.python-environments/default/lib/python2.7/site-packages/epc/__init__.pyc")
 (:version "0.0.3" :name "sexpdata" :file "/Users/shohei.yoshida/.emacs.d/.python-environments/default/lib/python2.7/site-packages/sexpdata.pyc"))
jwintz commented 7 years ago

Unfortunately, M-x jedi:show-version-info triggers exactly the same errors.

jwintz commented 7 years ago

Actually, I got it working by commenting the following:

;; (setq jedi:environment-root prolusion-jedi-dir)                                                                                                             
;; (setq python-environment-directory prolusion-jedi-dir)                                                                                                      
;; (setq python-environment-default-root-name "root")

So I guess that jedi does not work with custom directories, how could this be fixed ?

jwintz commented 7 years ago

By commenting the overload of the python-environment-directory, M-x jedi:show-version-info shows the expected result:

(:emacs-version "25.1.50.1" :jedi-version "0.2.7")
((:version "2.7.12 (default, Oct 11 2016, 15:53:37) \n[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)]" :name "sys" :file nil)
 (:version "0.9.0" :name "jedi" :file "/Users/jwintz/.emacs.d/.python-environments/default/lib/python2.7/site-packages/jedi/__init__.pyc")
 (:version "0.0.5" :name "epc" :file "/Users/jwintz/.emacs.d/.python-environments/default/lib/python2.7/site-packages/epc/__init__.pyc")
 (:version "0.0.3" :name "sexpdata" :file "/Users/jwintz/.emacs.d/.python-environments/default/lib/python2.7/site-packages/sexpdata.pyc"))
jwintz commented 7 years ago

I finally got it working with custom paths. The key was to delete the following two statements:

(autoload 'jedi:setup "jedi" nil t)                                                                                                                         
(add-hook 'python-mode-hook 'jedi:setup)  

Thanks !