Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jedi ignores current virtualenv? #345

Open
N214 opened this issue Dec 12, 2019 · 7 comments
Open

Jedi ignores current virtualenv? #345

N214 opened this issue Dec 12, 2019 · 7 comments

Comments

@N214
Copy link

N214 commented Dec 12, 2019

Jedi setup

;; Emacs Lisp version:
(:emacs-version "26.3" :jedi-version "0.2.7" :python-environment-version "0.0.2alpha0")
;; Python version:
nil
;; EPC error:
(:get-epc-error
 (wrong-type-argument epc:manager nil))
;; Command line:
(:virtualenv "/home/n214/.local/bin/virtualenv" :virtualenv-version "16.7.8\n")
;; Customization:
((jedi:complete-on-dot . t)
 (jedi:doc-display-buffer . display-buffer)
 (jedi:doc-hook view-mode)
 (jedi:doc-mode . rst-mode)
 (jedi:environment-root)
 (jedi:environment-virtualenv)
 (jedi:get-in-function-call-delay . 1000)
 (jedi:get-in-function-call-timeout . 3000)
 (jedi:goto-definition-config
  (nil nil nil)
  (t nil nil)
  (nil definition nil)
  (t definition nil)
  (nil nil t)
  (t nil t)
  (nil definition t)
  (t definition t))
 (jedi:goto-definition-hook)
 (jedi:goto-definition-marker-ring-length . 16)
 (jedi:imenu-create-index-function . jedi:create-nested-imenu-index)
 (jedi:import-python-el-settings . t)
 (jedi:install-imenu)
 (jedi:install-python-jedi-dev-command "pip" "install" "--upgrade" "git+https://github.com/davidhalter/jedi.git@master#egg=jedi")
 (jedi:key-complete .
		    [C-tab])
 (jedi:key-goto-definition .
			   [67108910])
 (jedi:key-goto-definition-pop-marker .
				      [67108908])
 (jedi:key-related-names . "�r")
 (jedi:key-show-doc . "�d")
 (jedi:server-args)
 (jedi:server-command "python" "/home/n214/.emacs.d/elpa/jedi-core-20190620.1820/jediepcserver.py")
 (jedi:setup-keys)
 (jedi:tooltip-method pos-tip popup)
 (jedi:use-shortcuts)
 (python-environment-default-root-name . "default")
 (python-environment-directory . "/home/n214/.virtualenvs/")
 (python-environment-virtualenv "virtualenv" "--system-site-packages" "--quiet"))

Error (jedi):


================================
Failed to start Jedi EPC server.
================================

*** EPC Error ***
Server may raise an error. Use "M-x epc:pop-to-last-server-process-buffer RET" to see full traceback:
Cannot create environment for '/home/n214/.pyenv/versions/venv1/'
Traceback (most recent call last):
  File "/home/n214/.emacs.d/.python-environments/default/lib/python3.6/site-packages/jediepcserver.py", line 118, in jedi_create_environment
    return _cached_jedi_environments[venv]
KeyError: '/home/n214/.pyenv/versions/venv1/'

During handling of the above exception, another exception occurred:


*** EPC Server Config ***
Server arguments: ("/home/n214/.emacs.d/.python-environments/default/bin/jediepcserver" "--virtual-env" "/home/n214/.pyenv/versions/venv1/" "--virtual-env" "/home/n214/.virtualenvs/env1" "--virtual-env" "/home/n214/.virtualenvs/env2")
Actual command: /home/n214/.emacs.d/.python-environments/default/bin/jediepcserver
VIRTUAL_ENV envvar: nil

I don't understand why I always have this argument even if I have (setq jedi:server-args '("--virtual-env" "/home/n214/.virtualenvs/env1") in my config

--virtual-env" "/home/n214/.pyenv/versions/venv1/"

@immerrr
Copy link
Collaborator

immerrr commented Dec 12, 2019

What does the full traceback in epc:pop-to-last-server-process-buffer say?

Looks like the server has three virtual-env parameters set:

("/home/n214/.emacs.d/.python-environments/default/bin/jediepcserver" 
"--virtual-env" "/home/n214/.pyenv/versions/venv1/" 
"--virtual-env" "/home/n214/.virtualenvs/env1" 
"--virtual-env" "/home/n214/.virtualenvs/env2")

One of those is the one that you are mentioning, the other two come elsewhere. The first step I would suggest is to try disabling jedi:import-python-el-settings that might be picking up some configuration from python-mode settings.

@N214
Copy link
Author

N214 commented Dec 13, 2019

The two other virtual envs are set by myself in my config, but for the first one I don't know where it's coming from?

@immerrr
Copy link
Collaborator

immerrr commented Dec 15, 2019

Like I said, try disabling jedi:import-python-el-settings and see if it helps.

Also, issue title is a bit confusing as I'm not sure which virtualenv do you consider "ignored" in this situation.

@N214
Copy link
Author

N214 commented Dec 24, 2019

Even deseabling jedi:import-python-el-settings
I still have this error.

Screenshot from 2019-12-24 11-39-37

@slackline
Copy link

Not sure if this will help but after encountering this error I found that I could solve it by installing the stable version of Elpy which was providing the EPC server.

@zkytony
Copy link

zkytony commented Aug 8, 2021

I resolved this by first removing ~/.emacs.d/.python-environments then reinstalling emacs-jedi. To make jedi be aware of current virtualenv I'm using the following config:

;; set the correct virtualenv path (current one)
(setq jedi:environment-virtualenv
      (list (shell-command-to-string "which python")))

I believe this avoids hard-coding the virtualenv path in the config file.

@mhuang001
Copy link

Goto-definition didn't work if the word was in a different file. Somehow monkeypatch couldn't be imported from jedi.common so the server stopped working. I spent a day fooling around with which virtual env is used by what...

I resolved this by first removing ~/.emacs.d/.python-environments then reinstalling emacs-jedi.

Following this I went ahead and cloned the emacs-jedi repo and installed it with python -m pip install -e . then installed the server manually according to the doc. Everything works now.
oh I found that there were 1.17.2, 1.18.0, and 1.18.1 three versions of jedi in my site-package. I had to run 'pip uninstall jedi' three times before installing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants