How do I run a python interpreter in Emacs?

2020-05-19 04:55发布

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?

8条回答
太酷不给撩
2楼-- · 2020-05-19 05:07

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).

查看更多
Emotional °昔
3楼-- · 2020-05-19 05:13

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

查看更多
看我几分像从前
4楼-- · 2020-05-19 05:13

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.

查看更多
叛逆
5楼-- · 2020-05-19 05:13

You probably need to have Python in your windows PATH environment variable. Can you start the interpreter just by typing python in the command window?

I don't have anything special in my emacs.el, but the start interpreter command works just fine.

Also, I recommend reading this blog post, as it contains many useful tips and packages worth installing if using Emacs as a Python IDE.

查看更多
何必那么认真
6楼-- · 2020-05-19 05:15

Place this in your .emacs to let emacs know where is your python interpretor

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

To learn about.emacs you can read about it in Emacs itself.(Emacs comes with good info manuals and info mode to help to read that manual).

press the following in emacs

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

查看更多
7楼-- · 2020-05-19 05:25

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")
查看更多
登录 后发表回答