3

Using Mac OSC 10.13.4, emacs 25.3 (9.0), Python3

I could have some cases of Elpy autocompletion to work for python3, but for some reason, not always.
For example,

numpy.

triggers autocompletion, but,

pandas.

does not.

My intuition is that while numpy comes standard with python3, pandas does not. So I need to have emacs to point to the directory where the add-on modules are located. In short, emacs does not use the same paths as python3 ... I tried to add a path to the current emacs paths, but it always failed to append these. How can I do that?

Numpy gets autocompletion but pandas does not

Cy Bu
  • 1,401
  • 2
  • 22
  • 33
  • 1
    Numpy doesn't come standard with Python 3; it's a third-party library, just like Pandas, and they're most likely installed into the same site-packages (assuming you did the same pip or conda or whatever commands to install them). – abarnert Apr 24 '18 at 17:55
  • OK, my intuition was incorrect. And yes I installed with the same pip. I still need to have emacs "see" pandas. any lead? – Cy Bu Apr 24 '18 at 18:09
  • Do you have multiple Python, both with numpy installed but only one with pandas, and have emacs pointing at the wrong one? – abarnert Apr 24 '18 at 18:10
  • I don't believe so. when I do '```pip show ```, i get: /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages for both pandas and numpy. – Cy Bu Apr 24 '18 at 18:15
  • 1
    Actually, if you're on macOS, you _do_ have multiple Pythons, whether you know it or not, and the other one probably does have numpy but not pandas, and it probably doesn't even have pip. And most likely that's the one elpy is seeing. I've written an answer to explain in detail, including how you can verify whether that is or is not your actual problem. – abarnert Apr 24 '18 at 18:37
  • As a side note: please don't post screenshots of code or other text; just copy and paste the text. – abarnert Apr 24 '18 at 18:53

1 Answers1

3

The problem is almost certainly that elpy isn't using the same Python you think it is.

Since you're on macOS, you have at least one other Python—Apple's pre-installed version of Python 2.7 in /usr/bin/python. And in most versions of macOS, this includes a special "Extras" directory full of stuff that doesn't normally come builtin with Python—which includes numpy, but not pandas, and in some versions not even pip.

So, your pip show numpy and pip show pandas are using the Python 3.5 pip, because that's the only pip you have.

But if elpy is finding Apple's Python 2.7 rather than the Python 3.5 you installed, it will find the Extras numpy and won't find any pandas.

You should also see other weird misbehaviors, like elpy trying to complete print as the Python 2.x statement rather than the Python 3.x function—but the easiest way to diagnose the problem is not to dive into all of those details, and instead just M-x elpy-config. It should show 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 whatever the appropriate path is to your Python 3.5).

I believe just configuring elpy-rpc-python-command will cause it to pick up everything else properly. Or you can just do it from within elpy-config itself. But that's probably a better question for emacs.SE than the Python tag on SO.

abarnert
  • 354,177
  • 51
  • 601
  • 671
  • You have a very point there: when I run pip from the M-x eshell, it tells me that pip is not installed. although my elpy-config shows: { Virtualenv........: None RPC Python........: 3.5.2 (/usr/local/bin/python3) Interactive Python: /usr/local/bin/python3 (/usr/local/bin/python3) Emacs.............: 25.3.1 Elpy..............: 1.19.0 Jedi..............: 0.12.0 Rope..............: 0.10.7 Autopep8..........: 1.3.5 Yapf..............: 0.21.0 Syntax checker....: Not found (flake8 [...] The directory ~/.local/bin/ is not in your PATH [...] } – Cy Bu Apr 24 '18 at 18:46
  • @CyBu You can't format things usefully in comments. But fortunately, all of that information belongs in your question, to help anyone else who tries to debug your error for you, or any future questioners with similar problems, and of course you can edit the question and format it nicely there. – abarnert Apr 24 '18 at 18:53