40

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.

1
  • I hope you mean /usr/local/bin
    – mmmmmm
    Oct 19, 2015 at 21:54

3 Answers 3

28

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.

7
  • 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, 2015 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 Sep 15, 2015 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. Jun 1, 2016 at 15:19
  • 1
    (elpy-use-ipython) is deprecated; see elpy.readthedocs.io/en/latest/ide.html#interpreter-setup Jun 1, 2018 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 4, 2020 at 19:55
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
2
  • 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, 2018 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.
    – xdavidliu
    Mar 14, 2018 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.