jorgenschaefer / elpy

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

Annoying "version mismatch" popups #1137

Open offby1 opened 7 years ago

offby1 commented 7 years ago

I recently upgraded the elisp component of elpy from http://jorgenschaefer.github.io/packages/ and got version 1.15.1. The most current version of the python component is 1.15.0. And thus I occasionally see a popup that says

Elpy Version Mismatch                                                                                                                                                                                                                                                                                                                                

You are not using the same version of Elpy in Emacs Lisp compared to
Python. This can cause random problems. Please do make sure to use
compatible versions.

Elpy Emacs Lisp version: 1.15.1
Elpy Python version....: 1.15.0

This is annoying, since the only way I can think of that will make it shaddap is to downgrade the elisp.

jorgenschaefer commented 7 years ago

The Elpy Emacs package comes with the Python code, you should not have to install the elpy package in the virtualenv at all! :-)

jerryasher commented 7 years ago

I'm running into the same problem as @offby1 and I don't understand

The Elpy Emacs package comes with the Python code, you should not have to install the elpy package in the virtualenv at all! :-)

Using Win 7 64, cygwin 32 and cygwin python2.7, I had to explicitly set '(elpy-rpc-python-command "python2.7") in the emacs options, since cygwin uses a funky cygwin symbolic link to link python2.7 to python.

And so with the python elpy package NOT installed, elpy-config reports

Elpy Configuration

Virtualenv........: None
RPC Python........: 2.7.13 (c:/cygwin/bin/python2.7.exe)
Interactive Python: ipython (not found)
Emacs.............: 25.1.1
Elpy..............: Not found (Python), 1.15.1 (Emacs Lisp)
Jedi..............: 0.10.2
Rope..............: Not found (0.10.5 available)
Importmagic.......: 0.1.7
Autopep8..........: 1.3.1
Yapf..............: 0.16.2
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 Python interpreter could not find the elpy module. Make sure the
module is installed.

[run] python2.7 -m pip install --user elpy

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] python2.7 -m pip install --user flake8

Since elpy-config is telling me to install elpy, I guess I will...?

$ pip2 install elpy
Collecting elpy
  Using cached elpy-1.15.0-py2.py3-none-any.whl
Requirement already satisfied: importmagic in /usr/lib/python2.7/site-packages (from elpy)
Requirement already satisfied: flake8>=2.0 in /usr/lib/python2.7/site-packages (from elpy)
Requirement already satisfied: setuptools>=0.6b1 in /usr/lib/python2.7/site-packages (from importmagic->elpy)
Requirement already satisfied: enum34; python_version < "3.4" in /usr/lib/python2.7/site-packages (from flake8>=2.0->elpy)
Requirement already satisfied: configparser; python_version < "3.2" in /usr/lib/python2.7/site-packages (from flake8>=2.0->elpy)
Requirement already satisfied: pycodestyle<2.4.0,>=2.0.0 in /usr/lib/python2.7/site-packages (from flake8>=2.0->elpy)
Requirement already satisfied: mccabe<0.7.0,>=0.6.0 in /usr/lib/python2.7/site-packages (from flake8>=2.0->elpy)
Requirement already satisfied: pyflakes<1.6.0,>=1.5.0 in /usr/lib/python2.7/site-packages (from flake8>=2.0->elpy)
Requirement already satisfied: appdirs>=1.4.0 in /usr/lib/python2.7/site-packages (from setuptools>=0.6b1->importmagic->elpy)
Requirement already satisfied: packaging>=16.8 in /usr/lib/python2.7/site-packages (from setuptools>=0.6b1->importmagic->elpy)
Requirement already satisfied: six>=1.6.0 in /usr/lib/python2.7/site-packages (from setuptools>=0.6b1->importmagic->elpy)
Requirement already satisfied: pyparsing in /usr/lib/python2.7/site-packages (from packaging>=16.8->setuptools>=0.6b1->importmagic->elpy)
Installing collected packages: elpy
Successfully installed elpy-1.15.0

elpy-config now reports:

Elpy Configuration

Virtualenv........: None
RPC Python........: 2.7.13 (c:/cygwin/bin/python2.7.exe)
Interactive Python: ipython (not found)
Emacs.............: 25.1.1
Elpy..............: 1.15.0 (Python), 1.15.1 (Emacs Lisp)
Jedi..............: 0.10.2
Rope..............: Not found (0.10.5 available)
Importmagic.......: 0.1.7
Autopep8..........: 1.3.1
Yapf..............: 0.16.2
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 Elpy backend is version 1.15.0 while the Emacs package is
1.15.1. This is incompatible. Please upgrade the Python module.
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] python2.7 -m pip install --user flake8

So while it now finds elpy, the incompatibility message still pops up.


I then create a virtualenv

$ virtualenv -p `which python2.7` ~/venv/py2
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in /C/users/jerry/venv/py2/bin/python2.7
Also creating executable in /C/users/jerry/venv/py2/bin/python
Installing setuptools, pip, wheel...done.

Back in emacs, I use pyvenv-activate and then elpy-config reports:

Elpy Configuration

Virtualenv........: py2 (c:/users/jerry/venv/py2)
RPC Python........: 2.7.13 (c:/cygwin/bin/python2.7.exe)
Interactive Python: ipython (not found)
Emacs.............: 25.1.1
Elpy..............: 1.15.0 (Python), 1.15.1 (Emacs Lisp)
Jedi..............: 0.10.2
Rope..............: Not found (0.10.5 available)
Importmagic.......: 0.1.7
Autopep8..........: 1.3.1
Yapf..............: 0.16.2
Syntax checker....: Not found (flake8)

The Elpy backend is version 1.15.0 while the Emacs package is
1.15.1. This is incompatible. Please upgrade the Python module.
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] python2.7 -m pip install flake8

ALSO FWIW, flake8 has been installed, though seemingly elpy cannot find it.

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

$ pip2 list | grep flake8                                                                                              
flake8                       3.3.0                                                                                     

Thanks for elpy in general, and any advice here.

jorgenschaefer commented 7 years ago

Huh. Elpy sets PYTHONPATH to include the Elpy package that ships with it. Very strange. This seems like a bigger problem than just Elpy not being found. In any case, the Elpy package on PyPI is now updated, so that should work, at least.

As for flake8, try to find out which directory the flake8 script is installed in.

jerryasher commented 7 years ago

Thanks, I upgraded elpy so that helps.

flake8 still can't be found, but on investigation followed by googling, the reason is explained here: https://github.com/flycheck/flycheck/issues/146

This may be because flycheck-check-executable is trying to run executable-find directly on flake8 instead of running it as an argument to python, which is what is needed on Windows, which doesn't support shebang lines natively.

elpy also uses executable-find to search for flake8 and won't find it, even though it's "x" bits are set and it is in the path.

Sigh. I just switched to cygwin python on a native emacs away from native python because I do use cygwin bash as a command shell and have not wanted to switch to msys2, and native python also doesn't support cygwin paths that bash sends it. (Small rant, cygwin has been around for 22 years, there are some far younger apps (cough native python cough) I wish would support it.) (Oh well, I'm an idiot for running Windows...) (anaconda doesn't support cygwin either).

There's a workaround suggested in the flycheck issue, I will look into adding that into my witches brew of a .init.el.

jorgenschaefer commented 7 years ago

That sounds like some might pain right there … you can probably set python-check-command to python -m flake8 or something? Sorry, I do not have access to Windows, so not much help here :-(

jerryasher commented 7 years ago

I seem to have fixed it for now by cheating. I did have a native python install (that I was using till yesterday), and when I had earlier installed flake8 into it, it installed a native flake8.exe onto my system. So I copied that out and plopped it into a directory on my path, and that seems to found and work just fine.

offby1 commented 7 years ago

This might be a clue: I saw the same behavior on a different system, and I notice

elpy-rpc-pythonpath is a variable defined in ‘elpy.el’.
Its value is "/home/ec2-user/.emacs.d/elpa/elpy-20170401.1152/"
Original value was
"/home/ec2-user/.emacs.d/elpa/elpy-20170513.215/"

  This variable is safe as a file local variable if its value
  satisfies the predicate ‘file-directory-p’.

Documentation:
A directory to add to the PYTHONPATH for the RPC process.

This should be a directory where the elpy module can be found. If
this is nil, it’s assumed elpy can be found in the standard path.
Usually, there is no need to change this.

The first directory (the one with 0401 in its name) doesn't exist, but the second one does.

jerryasher commented 7 years ago

Jorgen, do you have any interest in having both elpy and pyvenv better support cygwin python in a native windows emacs?

I think it's a useful mix of platforms as

That led me (and maybe others) to running native windows emacs for the speed and cygwin python and cygwin bash for the shell and the shell compatibility.

And that mostly works fine. Pyvenv actually works fine with cygwin python virtual envs by "misdetecting" virtual env directories as Unix.

But elpy in native windows emacs, does not work with cygwin python virtual env as it uses a windows native definition of find-executable and so doesn't find cygwin python scripts and executables.

Assuming I can add something useful to take out some of these rough edges, where is the best place to discuss various design details of both elpy and pyvenv? As issues here? On IRC? Via email?

offby1 commented 7 years ago

For what it's worth: my one machine which still had this problem is now cured. Here's what I did:

offby1 commented 6 years ago

This just happened again, and my recipe above let me get past it. I don't know why it happened; perhaps I thoughtlessly ran /home/erichan/python2.7/bin/pip install elpy.

In any case, it'd be helpful if the message about the mismatch could somehow hint at the real problem -- in my case, the problem is not that the right version of elpy wasn't available, but was that the right version of elpy was shadowed by an older version. That is, I had two versions on my PYTHONPATH, and the first one was the wrong one.

I don't know if python has anything like emacs' list-load-path-shadows, but if it did, it'd be helpful for that output to appear along with the warning about an elpy version mismatch; that way it'd be easier to figure out what to do about it.

offby1 commented 6 years ago

Another idea: I suspect I "thoughtlessly ran pip install elpy" because elpy-config suggests that I do so. I don't know why elpy suggests that (well, presumably it suggests that if it can't import elpy.py, but I don't know why it sometimes can't do that), but that manually-installed elpy package is probably why I occasionally get the version mismatch warning: I upgrade elpy with package-install, so the elisp version increases, but the manually-installed python package is now out of date compared to the elisp.