Inaimathi
Inaimathi

Reputation: 14065

How do I change the default command for `run-python`?

I'm starting on a Python 3 project, so I'd like to configure Emacs' run-python command to use the python3 interpreter by default.

I don't want to

I've tried setting python-which-shell to "python3" in my .emacs, but this doesn't seem to work.

Upvotes: 3

Views: 371

Answers (2)

Dan Jacka
Dan Jacka

Reputation: 1782

On Emacs 24.3, add to your .emacs:

(setq python-shell-interpreter "python3")

If this doesn't work on an older Emacs with a different Python mode, try M-x find-function RET run-python RET to inspect the source for an equivalent variable that can be set.

Upvotes: 4

Chris Doggett
Chris Doggett

Reputation: 20757

You can use the shebang line to specify which version you want to run:

#!/usr/bin/env python

Will use whichever one the system considers "python"

#!/usr/bin/env python2.6
#!/usr/bin/env python2.7
#!/usr/bin/env python3.2

Will run the specified version if you have more than one installed.

A friend taught me this when our Ops guy set up a VM with 2.6 and 2.7 installed, and I required 2.7, while the CentOS package manager required 2.6. Saved me a lot of having to go back and make things 2.6-compatible.

Upvotes: 0

Related Questions