pythonemacspipmacportsflymake

Emacs elpy Flymake can't find pyflakes even though pyflake has been installed by pip


After using macports pip-2.7 to install pyflakes, I can run it manually from the pip installation directory using the command line like:

python /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyflakes myfile.py

However, I'm trying to get my mac emacs environment setup with elpy, and flymake seems to not be able to find pyflakes, giving me a dialog when I open up a python file in elpy mode saying:

Flymake: Failed to launch syntax check process 'pyflakes' (with args myfile.py): Searching for program: no such file or directory, pyflakes. Flymake will be switched off.

I could go into /opt/local/bin and try to write my own executable file that runs the above python command. But that seems hacky and there must be a proper way to install/setup pyflakes such that flymake can find the command without manually creating wrapper scripts, isn't there?


Solution

  • I can run it manually from the pip installation directory using the command line like:

    python /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyflakes myfile.py
    

    Unless this directory is in your $PATH, Emacs has no way to know where to find pyflakes.

    One option would be to create a symbolic link, e.g.

    ln -s /opt/local/.../python2.7/site-packages/pyflakes /opt/local/bin/pyflakes
    

    Of course, you will have to use the full path. I shortened it for readability. This is relatively common on Linux machines, though I don't know how broadly it is used on OSX.

    Another option, one which I prefer, would be to reinstall pyflakes using pip install's --user option:

    --user 
    

    Install to the Python user install directory for your platform. Typically ~/.local/, or %APPDATA%Python on Windows. (See the Python documentation for site.USER_BASE for full details.)

    --user is great for installing things that you might want to run independently of any particular project, like pyflakes. It installs things to your home directory instead of to a system directory, so you don't need any elevated privileges to use it.

    You may have to add the user location to your $PATH variable, but you'll only have to do this once. Any future tools installed using pip install --user will become available immediately.

    On my Linux machine, the directory that I had to add to my $PATH is ~/.local/bin/.