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

elpy-goto-definition is broken, asks for jedi. elpy-config shows that jediis recognized #1795

Open
alienbogart opened this issue May 18, 2020 · 15 comments

Comments

@alienbogart
Copy link

Summary

I'm getting this message when trying to run elpy-goto-definition:

elpy-rpc-warn-if-jedi-not-available: This feature requires the ‘jedi‘ package to be installed. Please check ‘elpy-config‘ for more information., even though elpy-config correctly identifies jedi doesn't show any error.

Steps to reproduce

Run elpy-goto-definition on any object.

My configuration

OS

macOS Mojave 10.14.6

Result of (elpy-config)

# Paste it here

Elpy configuration in my init.el

Elpy Configuration

Emacs.............: 27.0.91
Elpy..............: 1.33.0
Virtualenv........: None
Interactive Python: python 3.8.2 (/Users/mrbig/.pyenv/shims/python)
RPC virtualenv....: .pyenv (/Users/mrbig/.pyenv)
 Python...........: python 3.8.2 (/Users/davi/.pyenv/shims/python)
 Jedi.............: 0.17.0
 Rope.............: 0.16.0
 Autopep8.........: 1.5.2
 Yapf.............: 0.30.0
 Black............: 19.10b0
Syntax checker....: flake8 (/Users/mrbig/.pyenv/shims/flake8)

Warnings

You have not activated a virtual env. While Elpy supports this, it is often a
good idea to work inside a virtual env. You can use M-x pyvenv-activate or M-x
pyvenv-workon to activate a virtual env.

Options

Square brackets indicate buttons; type RET or click mouse-1 on a button to
invoke its action. Invoke [+] to expand a group, and [-] to collapse an expanded
group. Invoke the [Group], [Face], and [Option] buttons below to edit that item
in another window.

[+]-- [Group] Elpy
[+]-- [Group] Python
[+]-- [Group] Virtual Environments (Pyvenv)
[+]-- [Group] Completion (Company)
[+]-- [Group] Call Signatures (ElDoc)
[+]-- [Group] Inline Errors (Flymake)
[+]-- [Group] Code folding (hideshow)
[+]-- [Group] Snippets (YASnippet)
[+]-- [Group] Directory Grep (rgrep)
[+]-- [Group] Search as You Type (ido)
[+]-- [Group] Django extension
[+]-- [Group] Autodoc extension

My Settings

@galaunay
Copy link
Collaborator

It somehow picks the wrong python binaries (/Users/davi/.pyenv/shims/python instead of /Users/mrbig/.pyenv/shims/python).

Could you check the results of the following snippet:

(with-elpy-rpc-virtualenv-activated
 (message "RPC binaries: '%s'" (executable-find elpy-rpc-python-command)))
(message "User binaries: '%s'" (executable-find elpy-rpc-python-command))

@alienbogart
Copy link
Author

The problem was solved by itself, and I'm not sure how.

@alienbogart
Copy link
Author

alienbogart commented Jun 26, 2020

The issue came back. It's exactly the same problem.

So I ran:

(with-elpy-rpc-virtualenv-activated
 (message "RPC binaries: '%s'" (executable-find elpy-rpc-python-command)))
(message "User binaries: '%s'" (executable-find elpy-rpc-python-command))

And the result was "User binaries: ’/Users/davi/.pyenv/shims/python’".

Here's my Elpy Config:

Elpy Configuration

Emacs.............: 27.0.91
Elpy..............: 1.34.0
Virtualenv........: None
Interactive Python: python 3.8.2 (/Users/davi/.pyenv/shims/python)
RPC virtualenv....: .pyenv (/Users/davi/.pyenv)
 Python...........: python 3.8.2 (/Users/davi/.pyenv/shims/python)
 Jedi.............: 0.17.1
 Rope.............: 0.16.0
 Autopep8.........: 1.5.3
 Yapf.............: 0.30.0
 Black............: 19.10b0
Syntax checker....: flake8 (/Users/davi/.pyenv/shims/flake8)

Warnings

You have not activated a virtual env. While Elpy supports this, it is often a
good idea to work inside a virtual env. You can use M-x pyvenv-activate or M-x
pyvenv-workon to activate a virtual env.

Options

Square brackets indicate buttons; type RET or click mouse-1 on a button to
invoke its action. Invoke [+] to expand a group, and [-] to collapse an expanded
group. Invoke the [Group], [Face], and [Option] buttons below to edit that item
in another window.

@galaunay
Copy link
Collaborator

I guess you are starting Emacs from an environment where pyenv is activated (as opposed to using pyenv-mode for example) ?

Elpy is failing to import the Jedi package for some reasons...
Could you run the following function from a buffer where the problem occur, and paste what is printed in the *Messages* buffer (after removing any sensitive information if necessary).

(defun elpy-tmp()
  (message "Outside RPC:")
  (message "    Python RPC: %s" (executable-find elpy-rpc-python-command))
  (message "    Python shell: %s" (executable-find python-shell-interpreter))
  (message "    Library-root: %s" (elpy-library-root))
  (message "    Env: %s" (car (elpy-rpc--environment)))

  (with-elpy-rpc-virtualenv-activated
   (message "Inside RPC:")
   (message "    Current env deactivated ?: %s"
            current-environment-is-deactivated)
   (message "    Python RPC: %s" (executable-find elpy-rpc-python-command))
   (message "    Python shell: %s" (executable-find python-shell-interpreter))
   (message "    Library-root: %s" (elpy-library-root))
   (message "    Env: %s" (car (elpy-rpc--environment)))))

Is is just printing some important variables that deals with the RPC.

@phulien
Copy link

phulien commented Dec 26, 2020

I have the same issue now. Below is elpy-tmp() output

Outside RPC:
    Python RPC: /usr/local/bin/python
    Python shell: /usr/local/bin/python3
    Library-root: ~/script/
    Env: PYTHONPATH=/Users/phu/.emacs.d/elpa/elpy-20201115.1811/:
Inside RPC:
    Current env deactivated ?: t
    Python RPC: /Users/phu/.emacs.d/elpy/rpc-venv/bin/python
    Python shell: /Users/phu/.emacs.d/elpy/rpc-venv/bin/python3
    Library-root: ~/script/
    Env: PYTHONPATH=/Users/phu/.emacs.d/elpa/elpy-20201115.1811/:
"    Env: PYTHONPATH=/Users/phu/.emacs.d/elpa/elpy-20201115.1811/:"

And output of elpy-config

Emacs.............: 27.1
Elpy..............: 1.35.0
Virtualenv........: None
Interactive Python: python3 3.9.1 (/usr/local/bin/python3)
RPC virtualenv....: rpc-venv (/Users/phu/.emacs.d/elpy/rpc-venv)
 Python...........: python 3.9.1 (/Users/phu/.emacs.d/elpy/rpc-venv/bin/python)
 Jedi.............: 0.18.0
 Rope.............: 0.18.0
 Autopep8.........: 1.5.4
 Yapf.............: 0.30.0
 Black............: 20.8b1
Syntax checker....: flake8 (/usr/local/bin/flake8)

@grauschnabel
Copy link

There was also a issue with jedi 0.18.0 on anaconda-mode. However they could solve it. Maybe its related. See their issue.

@luke-powers
Copy link

Having the same issue, providing some more context here.

My configuration
Ubuntu 20.10, GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.23, cairo version 1.16.0)
of 2021-02-02

Elpy Configuration

Emacs.............: 28.0.50
Elpy..............: 1.35.0
Virtualenv........: None
Interactive Python: python3 3.8.6 (/usr/bin/python3)
RPC virtualenv....: rpc-venv (/home/user/.emacs.d/elpy/rpc-venv)
Python...........: python3 3.8.6 (/home/user/.emacs.d/elpy/rpc-venv/bin/python3)
Jedi.............: 0.18.0
Rope.............: 0.18.0
Autopep8.........: 1.5.5
Yapf.............: 0.30.0
Black............: 20.8b1
Syntax checker....: flake8 (/home/user/.local/bin/flake8)

Elpy configuration in init.el (this is all that is in init.el)
(setq elpy-rpc-python-command "python3")

;; Add repos.
(require 'package)
(add-to-list 'package-archives
'("melpa" . "http://melpa.org/packages/") t)

Also, I installed jedi manually from elpa and, once jedi server is up and running, it navigates through the simple python files as expected, BUT elpy still says that jedi is not installed.

@wwade
Copy link

wwade commented Mar 16, 2021

I had the same issue on a slightly older emacs. For me, (re-)running jedi:install-server fixed the problem.

My entire environment is a little bit of a message undergoing python2 -> python3 upgrades, but it was working well for me earlier, and then I started seeing this issue.

Version:

"GNU Emacs 25.3.1 (i686-pc-linux-gnu, GTK+ Version 3.22.30) of 2020-06-11" 

elpy-tmp:

Outside RPC:                                                   
    Python RPC: /usr/bin/python2                               
    Python shell: /usr/bin/python                              
    Library-root: /src/                                        
    Env: PYTHONPATH=/home/me/.emacs.d/elpa/elpy-20210227.56/   
Inside RPC:                                                    
    Current env deactivated ?: t                               
    Python RPC: /home/me/.emacs.d/elpy/rpc-venv/bin/python2    
    Python shell: /home/me/.emacs.d/elpy/rpc-venv/bin/python   
    Library-root: /src/                                        
    Env: PYTHONPATH=/home/me/.emacs.d/elpa/elpy-20210227.56/   
"    Env: PYTHONPATH=/home/me/.emacs.d/elpa/elpy-20210227.56/" 

After this, I ran jedi:install-server and it started working again (after elpy-rpc-restart). The elpy-tmp output is identical afterward (even after restarting emacs, to be sure), but now elpy-goto-def works as before!

Elpy Configuration

Emacs.............: 25.3.1
Elpy..............: 1.35.0
Virtualenv........: None
Interactive Python: python 2.7.18 (/usr/bin/python)
RPC virtualenv....: rpc-venv (/home/me/.emacs.d/elpy/rpc-venv)
 Python...........: python2 2.7.18 (/home/me/.emacs.d/elpy/rpc-venv/bin/python2)
 Jedi.............: 0.17.2 (0.18.0 available)
 Rope.............: 0.18.0
 Autopep8.........: 1.5.6
 Yapf.............: 0.31.0
 Black............: Not found
Syntax checker....: pycheck (/home/me/bin/pycheck)

@lullis
Copy link

lullis commented Mar 17, 2021

Start facing this issue after upgrading elpy to 1.35 (I think). I am not sure if this happens only when trying to work with python2 projects or general (I can report later after checking with python3 codebase)

Output from the elpy-tmp

Outside RPC:
    Python RPC: /usr/bin/python
    Python shell: /usr/bin/python
    Library-root: ~/
    Env: PYTHONPATH=/home/raphael/.emacs.d/elpa/elpy-20210227.56/
env-diff nil
Inside RPC:
    Current env deactivated ?: t
    Python RPC: /home/raphael/.emacs.d/elpy/rpc-venv/bin/python
    Python shell: /home/raphael/.emacs.d/elpy/rpc-venv/bin/python
    Library-root: ~/
    Env: PYTHONPATH=/home/raphael/.emacs.d/elpa/elpy-20210227.56/
env-diff nil

I am curious about this env-diff nil I am seeing, it happens whenever I open a python file as well.

Output of elpy-config after disabling the virtualenv from the project

Elpy Configuration

Emacs.............: 26.3
Elpy..............: 1.35.0
Virtualenv........: None
Interactive Python: python 2.7.18 (/usr/bin/python)
RPC virtualenv....: rpc-venv (/home/raphael/.emacs.d/elpy/rpc-venv)
 Python...........: python 3.8.5 (/home/raphael/.emacs.d/elpy/rpc-venv/bin/python)
 Jedi.............: 0.18.0
 Rope.............: 0.18.0
 Autopep8.........: 1.5.6
 Yapf.............: 0.31.0
 Black............: 20.8b1
Syntax checker....: Not found (flake8)

Warnings

You have not activated a virtual env. It is not mandatory but often a
good idea to work inside a virtual env. You can use `M-x
pyvenv-activate` or `M-x pyvenv-workon` to activate one.

The configured syntax checker (flake8) could not be found. Elpy uses
this program to provide syntax checks of your code. You can either
install it, or select another one using `elpy-syntax-check-command`.

[Install flake8]

Options

`Raised' text indicates buttons; type RET or click mouse-1 on a button
to invoke its action.  Invoke [+] to expand a group, and [-] to
collapse an expanded group.  Invoke the [Group], [Face], and [Option]
buttons below to edit that item in another window.

@galaunay
Copy link
Collaborator

It may be a change in jedi 0.18 we are not supporting.
Could you try going back to jedi 0.17 and check if it works ?

@kiani45
Copy link

kiani45 commented Apr 6, 2021

It may be a change in jedi 0.18 we are not supporting.
Could you try going back to jedi 0.17 and check if it works ?

I haved tried 0.17 & 0.16, both has the same problem

@excalamus
Copy link

I'm using straight.el so that it's easy to checkout previous versions. What I'm confused about is I still can't find definitions with older versions.

For example, say I roll back to v1.34.0 (980705c), the last release. I rebuild elpy with straight-rebuild-package, restart Emacs, and verify that elpy-version is "1.34.0". The elpy release was made on May 27, 2020. Jedi 0.17.0 was released April 14, 2020, prior to elpy v1.34.0. Installing that in my environment yields for elpy-config:

Elpy Configuration

Emacs.............: 27.1
Elpy..............: 1.34.0
Virtualenv........: my-project-38 (c:/python/miniconda38/envs/my-project-38)
Interactive Python: ipython 7.22.0 (c:/python/miniconda38/envs/my-project-38/Scripts/ipython.exe)
RPC virtualenv....: envs (c:/python/miniconda38/envs)
 Python...........: python 3.8.8 (c:/python/miniconda38/envs/my-project-38/python.exe)
 Jedi.............: 0.17.0 (0.18.0 available)
 Rope.............: Not found (0.18.0 available)
 Autopep8.........: Not found (1.5.6 available)
 Yapf.............: Not found (0.31.0 available)
 Black............: Not found (20.8b1 available)
Syntax checker....: Not found (flake8)

I still can't find definitions.

Let me try rolling back further to elpy v1.33.0 (b69ae76). Do straight-rebuild-package, restart Emacs, verify "1.33.0". This release was made Mar 23, 2020. This corresponds to Jedi 0.16.0 released on Jan 25, 2020. This yields:

Elpy Configuration

Emacs.............: 27.1
Elpy..............: 1.33.0
Virtualenv........: my-project-38 (c:/python/miniconda38/envs/my-project-38)
Interactive Python: ipython 7.22.0 (c:/python/miniconda38/envs/my-project-38/Scripts/ipython.exe)
RPC virtualenv....: envs (c:/python/miniconda38/envs)
 Python...........: python 3.8.8 (c:/python/miniconda38/envs/my-project-38/python.exe)
 Jedi.............: 0.16.0 (0.18.0 available)
 Rope.............: Not found (0.18.0 available)
 Autopep8.........: Not found (1.5.6 available)
 Yapf.............: Not found (0.31.0 available)
 Black............: Not found (20.8b1 available)
Syntax checker....: Not found (flake8)

I still can't find definitions.

Now, I know that between Mar 23, 2020 and about a month or two ago, say Feb 1, 2021, I was able to find definitions. I'm not sure what prevents these rollbacks from working. Is it Python 3.8.8? Python 3.8 was released Oct. 14, 2019, so unless there's a bug within an older version, that ought not be the problem. Unfortunately, I'm bound to Python 3.8 by job requirements. I've been using Conda environments this whole time, again a work requirement. The packages are being seen, as reported by elpy-config so I don't think that's my issue.

I do see that elpy-config reports the RPC virtual env as c:/python/miniconda38/envs instead of c:/python/miniconda38/envs/my-project-38, which I would expect. Updating (setq elpy-rpc-virtualenv-path) doesn't appear to correct things. It's value prior to correction in current so it should be pulling from the active environment (and appears to be from the config).

Does anyone have a working configuration for Python 3.8? Can you please share your elpy-config so that we can get something that works until myself (or others) have time to figure out what changed in Jedi and how to update elpy to accommodate it?

For anyone needing a workaround, I am using ripgrep with rg.el to just search the project directory for the module I want.

@excalamus
Copy link

excalamus commented Apr 9, 2021

Here's a work around using dumb-jump.

Apparently, because I'm evil, I've been using xref-find-definitions and not elpy-goto-definition (when I press gd). That's good because xref-find-definitions uses xref-backend-functions to do the lookups.

However, simply adding another lookup function, like dumb-jump-xref-activate won't work:

;; won't work immediately; read on...
(add-hook 'xref-backend-functions #'dumb-jump-xref-activate)

It doesn't work because elpy adds a local hook when elpy-mode is enabled:

  ;; in define-miner-mode elpy-mode
  (when (boundp 'xref-backend-functions)
    (add-hook 'xref-backend-functions #'elpy--xref-backend nil t))

It's not clear to me how elpy--xref-backend works, exactly, but I'm certain of these two things:

  1. elpy--xref-backend is called prior to the dumb-jump-xref-activate hook, and
  2. it causes a failure such that dumb-jump-xref-activate is never called

Since the hook is applied locally, it's not as simple to remove, afaict, as (remove-hook 'xref-backend-functions #'elpy--xref-backend) (which removes it globally) or (remove-hook 'xref-backend-functions #'elpy--xref-backend t) (which only removes it from the current buffer). It's not apparent to me how to simply disable it; it looks to me like it would require editing the minor-mode definition. Otherwise, a hook could be added to elpy-mode-hook which removes the xref-backend-function. Another solution is to override the elpy--xref-backend:

;; add this and the dumb-jump hook will work
(advice-add 'elpy--xref-backend :override #'dumb-jump-xref-activate)

I've opted to take the advice route.

Now xref-find-definitions will work. The elpy-find-definition function will still fail because it relies on the RPC backend (i.e. jedi) which is having issues.

zed added a commit to zed/dotemacs.d that referenced this issue Apr 19, 2021
to workaround xref-find-definitions/elpy-goto-definition issue
jorgenschaefer/elpy#1795
zed added a commit to zed/dotemacs.d that referenced this issue Apr 19, 2021
to workaround xref-find-definitions/elpy-goto-definition issue
jorgenschaefer/elpy#1795
@yitang
Copy link

yitang commented Jun 24, 2021

I'm having the same issue.

tried @excalamus approach by using dumb-jump but M-. just hang.

managed to get M-. working by running lsp and lsp-jedi on top of elpy...

yitang added a commit to yitang/.emacs.d that referenced this issue Jun 24, 2021
@LuhengStat
Copy link

Here's a work around using dumb-jump.

Apparently, because I'm evil, I've been using xref-find-definitions and not elpy-goto-definition (when I press gd). That's good because xref-find-definitions uses xref-backend-functions to do the lookups.

However, simply adding another lookup function, like dumb-jump-xref-activate won't work:

;; won't work immediately; read on...
(add-hook 'xref-backend-functions #'dumb-jump-xref-activate)

It doesn't work because elpy adds a local hook when elpy-mode is enabled:

  ;; in define-miner-mode elpy-mode
  (when (boundp 'xref-backend-functions)
    (add-hook 'xref-backend-functions #'elpy--xref-backend nil t))

It's not clear to me how elpy--xref-backend works, exactly, but I'm certain of these two things:

  1. elpy--xref-backend is called prior to the dumb-jump-xref-activate hook, and
  2. it causes a failure such that dumb-jump-xref-activate is never called

Since the hook is applied locally, it's not as simple to remove, afaict, as (remove-hook 'xref-backend-functions #'elpy--xref-backend) (which removes it globally) or (remove-hook 'xref-backend-functions #'elpy--xref-backend t) (which only removes it from the current buffer). It's not apparent to me how to simply disable it; it looks to me like it would require editing the minor-mode definition. Otherwise, a hook could be added to elpy-mode-hook which removes the xref-backend-function. Another solution is to override the elpy--xref-backend:

;; add this and the dumb-jump hook will work
(advice-add 'elpy--xref-backend :override #'dumb-jump-xref-activate)

I've opted to take the advice route.

Now xref-find-definitions will work. The elpy-find-definition function will still fail because it relies on the RPC backend (i.e. jedi) which is having issues.

This method works quite well for me, thanks.

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

No branches or pull requests