sam
sam

Reputation: 171

Changing python interpreter for emacs

Emacs uses an older version of python(2.3) i have for the default python mode, is there a way for me to tell emacs to use the newer version that i have in my home directory?

btw I'm using a red hat distro and dont have root privileges.

Upvotes: 17

Views: 15100

Answers (5)

user3357359
user3357359

Reputation: 169

I know that the question is about a global python interpreter, but many can arrive here looking for the common problem of setting one python interpreter per project.

Supposing one has a virtualenv per project, a good solution is to set the python interpreter at .dir-local.el file located at the project root.

.dir-local.el example:

 (
  (python-mode . (
                 (python-shell-interpreter . "~/my_project/venv/bin/python")
                 (flycheck-checker . python-pylint)
                 (flycheck-python-pylint-executable . "~/myproject/venv/bin/python")
                 (flycheck-pylintrc . "~/my_project/.pylintrc")
                  )
   )
  )

Upvotes: 4

jpkotta
jpkotta

Reputation: 9417

python-python-command is for the older "loveshack python.el". For recent versions of Emacs, which use "gallina python.el", use the variable python-shell-interpreter.

(setq python-shell-interpreter "/path/to/python")

https://www.emacswiki.org/emacs/PythonProgrammingInEmacs#toc2

Upvotes: 8

Ray
Ray

Reputation: 192216

On Windows 10, I had two versions of Python installed:

  1. v3.5 installed under C:\ProgramData\chocolatey\bin
  2. v3.6 installed under C:\Program Files\Python36\

Emacs was using v3.5 but I preferred for it to use v3.6. Therefore, I did the following to correct this by editing my Environment Variables:

  1. Start -> Type in "environment variables"
  2. Select Edit the system environment variables -> Environment Variables...
  3. Under System variables, select Path variable -> Edit... -> New
  4. Add the path to your desired Python directory
  5. Click Move up to place the new filepath above whatever the other Python directory.

In my case for #4 & #5 above, I added C:\Program Files\Python36\ (v3.6 directory) and then moved it above C:\ProgramData\chocolatey\bin (v3.5 directory)

Upvotes: 0

radekg
radekg

Reputation: 459

It is good habit to check customize-group of things you wanna tweak. Just do:

M-x customize-group RET python RET

you've got now multiple options of which one should be interesting:

Python Python Command

You can customize it there and Save for further sessions.

Upvotes: 17

Chen Levy
Chen Levy

Reputation: 16358

Via .emacs:

Try to add to your ~/.emacs file:

(setq python-python-command "~/your/python/bin-dir/python")

or

Via the shell environment:

The python command that is run by Emacs is typically python, so you can try the simple approach of changing your path:

export PATH=~/your/python/bin-dir:$PATH

Upvotes: 9

Related Questions