Elpy: Elpy cannot find rope, jedi, autopep, yapf, or black in activated venv

Created on 14 Aug 2019  路  13Comments  路  Source: jorgenschaefer/elpy

Summary

Elpy cannot find the pip dependencies: Jedi, Rope, Autopep8, Yapf, Black

Steps to reproduce

1) Create venv
2) Activate venv
3) pip install jedi rope autopep8 Yapf black
4) start emacs in same directory (terminal process)
5) M-x elpy-config

My configuration

OS

MacOS Mojave 10.14.5

Result of (elpy-config)

Virtualenv........: dailyCode (/Desktop/emacs/dailyCode)
RPC Python........: 3.7.3 (/usr/local/bin/python3)
Interactive Python: jupyter (/Desktop/emacs/dailyCode/bin/jupyter)
Emacs.............: 26.1
Elpy..............: 1.30.0
Jedi..............: Not found (0.15.1 available)
Rope..............: Not found (0.14.0 available)
Autopep8..........: Not found (1.4.4 available)
Yapf..............: Not found (0.28.0 available)
Black.............: Not found (19.3b0 available)
Syntax checker....: flake8 (/Desktop/emacs/dailyCode/bin/flake8)

The directory ~/.local/bin/ is not in your PATH. As there is no active
virtualenv, installing Python packages locally will place executables
in that directory, so Emacs won't find them. If you are missing some
commands, do add this directory to your PATH -- and then do
`elpy-rpc-restart'.

Elpy configuration in my init.el

(add-to-list 'exec-path "/usr/local/bin")

;; Define package repositories
(require 'package)
(add-to-list 'package-archives
             '("tromey" . "http://tromey.com/elpa/") t)
(add-to-list 'package-archives
             '("melpa" . "http://melpa.milkbox.net/packages/") t)
(add-to-list 'package-archives
             '("melpa-stable" . "http://stable.melpa.org/packages/") t)

(add-to-list 'package-pinned-packages '(cider . "melpa-stable") t)
(add-to-list 'package-pinned-packages '(magit . "melpa-stable") t)

(package-initialize)

(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))
(require 'use-package)
Bug Can't reproduce More Info Needed

Most helpful comment

@Holt59 lt59
Flake8 is indeed installed in your current virtualenv.
But the other packages (jedi, rope, autopep8, yapf and black) are installed in a dedicated virtualenv for the RPC (/home/mikael.capelle/.emacs.d/elpy/rpc-venv).

In short, Elpy is searching for black in the RPC venv, not in your deel virtualenv.
If you want to use black, you need to install it in the RPC venv.
The problem is that black doesn't work with python2 (which is used for your RPC venv).

Doing this should work for you:

  • (setq elpy-rpc-python-command "python3")
  • M-x elpy-rpc-reinstall-virtualenv
  • Saying yes when asked to install python dependencies

All 13 comments

Hey,

I believe you would have to do M-x pyvenv-workon and choose the desired virtual env to activate it.

One way to get around always calling M-x pyvenve-workon is to create a .dir-locals.el file in the root of the python project and putting the following:

((nil
  (pyvenv-workon . "name-of-virtual-env")
))

This will activate the virtual env whenever you are in any file that is found within the root of that python project

~I just find I fall into the similar situation after upgrade yesterday...~

~rpc python just not use pyvenv as before...~

sorry, I just type wrong directory...

I just pyvenv-activate venv-directory specific venv when I should and everything works like a charm.

I guess you maybe set the wrong venv directory like I do? /Desktop/emacs/dailyCode do not like a virtualenv. Or you may not even pyvenv-workon or pyvenv-activate at all like gopar said

馃憤 for @gopar and @reverland.

The proper way of using virtualenvs in Elpy is to start Emacs outside of the virtualenv and use pyvenv-workon to activate it from inside.

Thanks for the solutions. I am a little bit disappointed because I was hoping it would work seamlessly with the venv tools that already exist. @galaunay Why does Elpy work out of the box with the standard venv?

I was worried that Elpy was using some variables set by pyvenv to interact properly with the virtualenv.
But I double-checked and starting Emacs in a virtualenv is indeed supposed to work.

The problem you have could be that Elpy is not finding elpy-rpc-python-command in your virtualenv, and then defaulting to the global one.

Could you give us the value of elpy-rpc-python-command and the result of (executable-find elpy-rpc-python-command) ?

@gopar, this is a nice tip!

One way to get around always calling M-x pyvenve-workon is to create a .dir-locals.el file in the root of the python project and putting the following:

((nil
  (pyvenv-workon . "name-of-virtual-env")
))

This will activate the virtual env whenever you are in any file that is found within the root of that python project

@galaunay, tip seems like this might fit under "IDE Features" as a Project-specific virtual environments (or similar) sub heading, rather than a FAQ entry. P.S. I have no idea if it interacts with projectile's method. ACK? @gopar, would you like to file the PR?

Maybe a silly comment, but I found this issue after search why my elpy didn't find rope, jedi, etc.

But the problem actually was due my recent update to python3.8. So I had to elpy-rpc-reinstall-virtualenv and then they showed up in elpy-config again.

So maybe it helps someone else who stumbles upon that in elpy after updating python.

I have a similar issue, and the above comments did nothing for me.

The following work in a terminal:

source ~/venv/bin/activate
black

If I start emacs outside of a virtual environment, and then use pyvenv-workon, black is not found by elpy, even if the virtual environment is correctly detected:

Elpy Configuration

Emacs.............: 26.3
Elpy..............: 1.32.0
Virtualenv........: deel (/home/mikael.capelle/venv/deel)
Interactive Python: ipython 7.9.0 (/home/mikael.capelle/venv/bin/ipython)
RPC virtualenv....: rpc-venv (/home/mikael.capelle/.emacs.d/elpy/rpc-venv)
 Python...........: python 2.7.5 (/home/mikael.capelle/.emacs.d/elpy/rpc-venv/bin/python)
 Jedi.............: 0.15.2
 Rope.............: 0.14.0
 Autopep8.........: Not found (1.4.4 available)
 Yapf.............: Not found (0.29.0 available)
 Black............: Not found (19.10b0 available)
Syntax checker....: flake8 (/home/mikael.capelle/venv/bin/flake8)

However, flake8 is found correctly... (executable-find elpy-rpc-python-command) returns the path to the virtual environment python as expected.

@Holt59 lt59
Flake8 is indeed installed in your current virtualenv.
But the other packages (jedi, rope, autopep8, yapf and black) are installed in a dedicated virtualenv for the RPC (/home/mikael.capelle/.emacs.d/elpy/rpc-venv).

In short, Elpy is searching for black in the RPC venv, not in your deel virtualenv.
If you want to use black, you need to install it in the RPC venv.
The problem is that black doesn't work with python2 (which is used for your RPC venv).

Doing this should work for you:

  • (setq elpy-rpc-python-command "python3")
  • M-x elpy-rpc-reinstall-virtualenv
  • Saying yes when asked to install python dependencies

@galaunay Thanks for the information. Why is flake8 treated differently from the other tools? I think it would be great to have a more detailed installation procedure, and what to install where.

I had to create the rpc-env manually with a python3 version because I did not manage to install it by setting elpy-rpc-python-command.

I think it was decided to treat flake8 differently to allow the use of other syntax checkers.
But you are right that it should be installed in the rpc.
I will have a look on how to do this when I have the chance to.

It may be worth checking elpy-rpc-virtualenv-path. The default is to use a dedicated virtualenv in .emacs.d/elpy. It can be set to work with the currently active environment:

(setq elpy-rpc-virtualenv-path 'current)

I guess this can be closed now.

Was this page helpful?
0 / 5 - 0 ratings