4

I am using emacs in python mode.

To run a python file I use the command C-c C-c.

Emacs automatically start to run python 2.7 while I would like to use python3.

Once I have been able to solve using this method link but now it is not working on ubuntu 14.04

How can I solve this?

2 Answers 2

4

Here's a solution which re-defines python-shell-parse-command:

(require 'python)
(defun python-shell-parse-command ()
  "Return the string used to execute the inferior Python process."
  "/usr/bin/python3 -i"
  )

Calling run-python invokes /usr/bin/python3 -i.


As a side note

There are two modes for python: python.el (default) and python-mode.el. You cite binding from python.el so I gave a solution for python.el. I just wanted to mention that python-mode.el has a built-in command for the task: python3.

2
  • I am not totally sure that I am using python.el hoe can n i checkthis?
    – Donbeo
    May 8, 2014 at 17:29
  • This works partially. Now when I use C-c C-c it runs the script on python3. The command C-c | used to evaluate only the lightened region does not work anymore
    – Donbeo
    May 9, 2014 at 9:55
3

Setting (setq python-shell-interpreter "python3") in .emacs should be enough

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .