jorgenschaefer / elpy

Emacs Python Development Environment
GNU General Public License v3.0
1.9k stars 262 forks source link

Elpy not detecting the installed flake8 #1002

Open lgp171188 opened 8 years ago

lgp171188 commented 8 years ago
Elpy Configuration

Virtualenv........: venv (/home/guruprasad/dev/py/treasure_hunt/venv)
RPC Python........: 3.5.2 (/home/guruprasad/dev/py/treasure_hunt/venv/bin/python)
Interactive Python: python (/home/guruprasad/dev/py/treasure_hunt/venv/bin/python)
Emacs.............: 25.1.1
Elpy..............: 1.12.0
Jedi..............: 0.9.0
Rope..............: Not found (0.10.3 available)
Importmagic.......: 0.1.7
Autopep8..........: Not found (1.2.4 available)
Yapf..............: Not found (0.12.1 available)
Syntax checker....: Not found (install pyflakes, pylint or something else)

Proof that flake8 is installed

(venv) ➜  treasurehunt git:(master) ✗ pip freeze | grep flake8
flake8==3.0.4
(venv) ➜  treasurehunt git:(master) ✗ which flake8
/home/guruprasad/dev/py/treasure_hunt/venv/bin/flake8
(venv) ➜  treasurehunt git:(master) ✗ 

Elpy is unable to detect the installed flake8 and hence the checker is unusable.

lgp171188 commented 8 years ago

This happens only when using a GUI instance of emacs and manually activating the virtualenv environment using pyvenv-activate. When launching emacs from terminal with virtualenv activated, things work fine.

lgp171188 commented 8 years ago

The value of python-check-command defined in python.el is overridden by python.el to the error message install pyflakes, pylint or something else when it cannot find pyflakes or epyflakes.

This is a bug since the elpy docs mention that flake8 is used as the default syntax checker but relies on python-check-command in python.el which doesn't even check for flake8.

python-check-command is a variable defined in ‘python.el’.
Its value is "install pyflakes, pylint or something else"
Original value was 
"/home/guruprasad/dev/py/treasure_hunt/venv/bin/pyflakes"

 This variable may be risky if used as a file-local variable.

Documentation:
Command used to check a Python file.

You can customize this variable.

Not sure if this issue is the same as #789, #789 or related to them.

ChillarAnand commented 8 years ago

Thanks for the report. I guess this is fixed in master. You can manually set full path to syntax checker in init.el or you can try using master?

offby1 commented 7 years ago

I'm seeing roughly the same behavior, but:

FWIW, here's the output of M-x elpy-config:

Elpy Configuration

Virtualenv........: None
RPC Python........: 2.7.12 (/home/erichan/python2.7/bin/python)
Interactive Python: /blah/blah/bin/python (/blah/blah/bin/python)
Emacs.............: 25.2.2
Elpy..............: 1.15.0
Jedi..............: Not found (0.10.2 available)
Rope..............: 0.10.5
Importmagic.......: 0.1.7
Autopep8..........: 1.3.1
Yapf..............: 0.16.1
Syntax checker....: Not found (flake8)

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.

The configured syntax checker could not be found. Elpy uses this
program to provide syntax checks of your programs, so you might want
to install one. Elpy by default uses flake8.

[run] /home/erichan/python2.7/bin/python -m pip install --user flake8

Options

Here's what I see when I click the "run" button:

Requirement already satisfied: flake8 in /local/home/erichan/python2.7/lib/python2.7/site-packages
Requirement already satisfied: mccabe<0.7.0,>=0.6.0 in /local/home/erichan/python2.7/lib/python2.7/site-packages (from flake8)
Requirement already satisfied: enum34; python_version < "3.4" in /local/home/erichan/python2.7/lib/python2.7/site-packages (from flake8)
Requirement already satisfied: configparser; python_version < "3.2" in /local/home/erichan/python2.7/lib/python2.7/site-packages (from flake8)
Requirement already satisfied: pyflakes<1.6.0,>=1.5.0 in /local/home/erichan/python2.7/lib/python2.7/site-packages (from flake8)
Requirement already satisfied: pycodestyle<2.4.0,>=2.0.0 in /local/home/erichan/.local/lib/python2.7/site-packages (from flake8)
jorgenschaefer commented 7 years ago

What's the output of M-: (executable-find "flake8")? Is the command in some directory that is not always in PATH?

offby1 commented 7 years ago

I think that was the hint that I needed! Here's what I had in ~/.emacs.d/init.el:

(use-package python
    :config
    (let ((exec-path
           (cons
            (expand-file-name (format "~/venv3.%s/bin" system-type))
            (cons
             (expand-file-name (format "~/venv2.%s/bin" system-type))
             exec-path))
           ))
      (setq python-check-command "flake8"
            python-shell-interpreter (or (executable-find "python3")
                                         (executable-find "python"))))
)

I changed "flake8" to (executable-find "flake8") and now it's working. Thanks!

jorgenschaefer commented 7 years ago

Great! :-)