emacs python Elpy autocomplete is not for everyone
Use Mac OSC 10.13.4, emacs 25.3 (9.0), Python 3
Some cases where I can get Elpy autocomplete work for python3, but not always for some reason.
For example,
numpy.
Trigger autocomplete, however
pandas.
No.
My gut feeling is that while numpy is standard on python3, pandas is not. So I need to point emacs to the directory where the add-in is located. In short, emacs does not use the same path as python3…
I tried to add paths to the current emacs path, but it always fails to append those paths. How can I do this?
Solution
It’s almost certain that elpy
uses a different Python than you think.
Because you’re on macOS, you have at least one other Python — Apple’s version of Python 2.7 pre-installed in /usr/bin/python
. In most versions of macOS, this includes a special “extras” directory filled with stuff that wouldn’t normally be built into Python — including numpy
, but not pandas
, and in some versions even pip
.
So, your pip show numpy
and pip show pandas
are using Python 3.5 pip, because that’s the only pip
you have.
But if elpy
is looking for Apple’s Python 2.7 instead of the Python 3.5 you installed, it will find Extras numpy
and will not find any pandas
You should also see other weird error behavior, such as elpy trying to complete print
as a Python 2.x statement instead of a Python 3.x function — but the easiest way to diagnose the problem isn’t to delve into all these details, but just M-x elpy-config
. It should display something like this:
Virtualenv........: None
RPC Python........: 2.7.10 (/usr/bin/python)
Interactive Python: python (/usr/bin/python)
Emacs.............: 25.3.0
…… etc
If so, the answer is that you need to fix the elpy
configuration to use /usr/local/bin/python3
(or any appropriate path for your Python 3.5).
I believe that just configuring elpy-rpc-python-command
will make it fetch everything else correctly. Or you can do it in elpy-config
itself. But this may be a better problem emacs.SE than Python tags on SO.