How to use python3 in emacs on ubuntu 14.04

5,474

Solution 1

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.

Solution 2

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

Share:
5,474

Related videos on Youtube

Donbeo
Author by

Donbeo

Updated on September 18, 2022

Comments

  • Donbeo
    Donbeo over 1 year

    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?

  • Donbeo
    Donbeo almost 10 years
    I am not totally sure that I am using python.el hoe can n i checkthis?
  • Donbeo
    Donbeo almost 10 years
    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