39

When setting up my emacs for a new work environment, I am unable to get the elpy configuration to correctly use python 3. I have installed all of the required packages in /usr/local/bin and have installed them using python3.

Right now, when I run elpy-config I am getting the following:

Virtualenv........: None
RPC Python........: 2.7.6 (/usr/bin/python)
Interactive Python: python (/usr/bin/python)
Emacs.............: 24.5.1
Elpy..............: 1.9.0
Jedi..............: 0.9.0
Rope..............: Not found (0.10.2 available)
Importmagic.......: 0.1.3
Autopep8..........: 0.1.3
Syntax checker....: Not found (pyflakes)

I would like to have RPC Python be ipython3 and the same for the interactive. For the purposes of this question, assume my .emacs file is blank.

Resigned June 2023
  • 1,502
  • 15
  • 20
adam
  • 491
  • 1
  • 4
  • 3

3 Answers3

27

You can conffigure elpy-rpc-python-command. If you want Python3 you can set it like this.

(setq elpy-rpc-python-command "python3")

Update

Create python3 virtualenv using virtualenvwrapper from terminal

$ mkvirtualenv test -p /usr/bin/python3

and then install required packages

$ pip install rope jedi importmagic autopep8 flake8

Now go to emacs, activate virtualenv and run M-x elpy-config

M-x pyvenv-workon test
M-x elpy-config

If you want to have ipython as your REPL, you can put this function in you config

(elpy-use-ipython)

or

(elpy-use-ipython "python3")

Note: elpy-use-ipython is deprecated. Use

(setenv "IPY_TEST_SIMPLE_PROMPT" "1")
(setq python-shell-interpreter "ipython3"
      python-shell-interpreter-args "-i")

or ipython based on your version.

Chillar Anand
  • 4,042
  • 1
  • 23
  • 52
  • Doing this and then going back into the config says that python3 is not recognized and Jedi, Importmagic, and autopep8 are now marked as `not found` – adam Sep 15 '15 at 18:12
  • You have to set full path to `python3`. If you are using ubuntu, you can use `/usr/bin/python3`. In any case, it is better if you create python3 virtual env, activate that env and install those packages. Updated answer – Chillar Anand Sep 15 '15 at 18:16
  • 2
    If you have ipython installed for Python2 and ipython3 installed for Python3, then you can use the ipython3 REPL with `(elpy-use-ipython "ipython3")` assuming that's in your path. – Viktor Haag Jun 01 '16 at 15:19
  • 1
    `(elpy-use-ipython)` is deprecated; see https://elpy.readthedocs.io/en/latest/ide.html#interpreter-setup – BallpointBen Jun 01 '18 at 15:27
  • The above made it worse as adam stated. I made a virtual env and did all the imports. elpy is not finding anything and insistse on stil suping elpy/repc-venv/bin/python as well which is what it was complaining about in the first place – sjatkins Jul 04 '20 at 19:55
  • Does ELPY have a variable inspector or a way to see my variables? – Emmanuel Goldstein Dec 07 '20 at 16:38
  • I don't think elpy has a variable inspector. You can use `helm-semantic-or-imenu` function to view variables, functions etc. @EmmanuelGoldstein – Chillar Anand Dec 08 '20 at 02:47
8

You can solve this by modifying the python shell configuration from python to python3 in elpy-config

  1. M-x elpy-config to enter the configuration page of elpy
  2. if you scroll down you will see groups with [+] signs, toggle the Python one and find the shell interpreter option: Option Python Shell Interpreter is the one you are looking for.
  3. If you click (or Enter in terminal version) on the Option button you will be able to edit the part "python" to "python3"
  4. Apply and save, and restart emacs
oksuzgonul
  • 81
  • 1
  • 1
  • I did this and `elpy-config` no longer opens: it says it cannot find `python3`. However, `python3` *is* in my path because I can issue it as a command in terminal no problem. For some reason emacs isn't actually capturing my full path. Is this a feature or a bug? I noticed it in many other packages requiring inferior shells as well. – xdavidliu Mar 14 '18 at 21:01
  • never mind, I'm on OSX and using gui emacs, and there's a really bad gotcha here that gui emacs (as opposed to terminal emacs) [doesn't capture my PATH variable](https://stackoverflow.com/questions/8606954/path-and-exec-path-set-but-emacs-does-not-find-executable). – xdavidliu Mar 14 '18 at 21:18
2

Set the interpreter variable in your .emacs file:

(setq python-shell-interpreter "python3"
      python-shell-interpreter-args "-i")

Taken from elpy manual

Stefan
  • 26,154
  • 3
  • 46
  • 84
init0
  • 31
  • 2