Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run a python interpreter in Emacs?

I just downloaded GNU emacs23.4, and I already have python3.2 installed in Windows7.

I have been using Python IDLE to edit python files.

The problem is that I can edit python files with Emacs but I do not know how to run python interpreter in Emacs. When i click on "switch to interpreter", then it says "Searching for program: no such file or directory, python"

Someone says i need to make some change on .emacs file, but i do not know where to look for.

And I am very unexperienced and just started to learn programming. I am not familiar with commonly used terminologies. I have been searching for solutions but most of the articles i find on the Internet only confuse me.

so the questions are:

  1. how do i run python interpreter in Emacs?
  2. are there different kind of python interpreter? if so, why do they have different interpreters for one language?
like image 748
Jeff Lee Avatar asked Apr 20 '12 06:04

Jeff Lee


People also ask

How do I run Python code in Emacs?

Once you open your python file in Emacs, you will need to start the python process with: M-x run-python or C-c C-p , which creates an inferior python shell buffer. This buffer will be created by a horizontal split, and the active buffer will be the one containing the python file.

What is Emacs ELPY?

Elpy is an Emacs package to bring powerful Python editing to Emacs. It combines and configures a number of other packages, both written in Emacs Lisp as well as Python. Elpy is fully documented at Readthedocs.


5 Answers

Place this in your .emacs file to set the location of your python interpreter:

 (setq python-shell-interpreter "path\to\your\python3.2")

Emacs comes with good manuals and an info mode to help read them. To learn more about .emacs you can use:

M-: (info "(Emacs)Init file") RET.

like image 181
kindahero Avatar answered Oct 31 '22 11:10

kindahero


C-c C-z can do this. It is the key-binding for the command python-switch-to-python

like image 45
Arjun Avatar answered Oct 31 '22 09:10

Arjun


In emacs 25.3.1 I use this to open up a python shell:

M-x run-python

After first adding this to my .emacs file:

(setq python-shell-interpreter "/usr/local/bin/python3")
like image 33
user8128167 Avatar answered Oct 31 '22 10:10

user8128167


IF you have python installed, try M-x python-shell (press and hold ALT while pressing x, then type python-shell, then press enter)

There are different language implementations if that is what you are asking (see a list of them here).

like image 8
Arnab Datta Avatar answered Oct 31 '22 09:10

Arnab Datta


In emacs 24.5.1 with spacemacs 105 (develop branch) and the Python layer enabled ("layer" is a spacemacs concept; see their documentation), I find python-shell-switch-to-shell opens an IPython buffer. I tested macropy.console in such a buffer and it works great.

like image 4
Reb.Cabin Avatar answered Oct 31 '22 11:10

Reb.Cabin