[英]How do I run a python interpreter in Emacs?
I just downloaded GNU emacs23.4, and I already have python3.2 installed in Windows7.我刚刚下载了GNU emacs23.4,并且我已经在Windows7中安装了python3.2。
I have been using Python IDLE to edit python files.我一直在使用 Python IDLE 来编辑 python 文件。
The problem is that I can edit python files with Emacs but I do not know how to run python interpreter in Emacs.问题是我可以用 Emacs 编辑 python 文件,但我不知道如何在 Emacs 中运行 python 解释器。 When i click on "switch to interpreter", then it says "Searching for program: no such file or directory, python"
当我点击“切换到解释器”时,它会显示“正在搜索程序:没有这样的文件或目录,python”
Someone says i need to make some change on .emacs file, but i do not know where to look for.有人说我需要对 .emacs 文件进行一些更改,但我不知道在哪里寻找。
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:所以问题是:
Place this in your .emacs
file to set the location of your python interpreter:将其放在您的
.emacs
文件中以设置 python 解释器的位置:
(setq python-shell-interpreter "path\to\your\python3.2")
Emacs comes with good manuals and an info mode to help read them. Emacs 带有很好的手册和信息模式来帮助阅读它们。 To learn more about
.emacs
you can use:要了解有关
.emacs
的更多信息,您可以使用:
M-: (info "(Emacs)Init file") RET . M-: (info "(Emacs)Init 文件") RET .
Cc Cz
can do this. Cc Cz
可以做到这一点。 It is the key-binding for the command python-switch-to-python
它是命令
python-switch-to-python
的键绑定
In emacs 25.3.1 I use this to open up a python shell:在 emacs 25.3.1 中,我使用它来打开一个 python shell:
M-x run-python
After first adding this to my .emacs file:首先将其添加到我的 .emacs 文件后:
(setq python-shell-interpreter "/usr/local/bin/python3")
IF you have python installed, try Mx python-shell
(press and hold ALT while pressing x, then type python-shell
, then press enter)如果您安装了 python,请尝试
Mx python-shell
(按住 ALT 的同时按 x,然后键入python-shell
,然后按 enter)
There are different language implementations if that is what you are asking (see a list of them here ).如果这是您所要求的,则有不同的语言实现(请参阅此处的列表)。
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.在带有spacemacs 105(开发分支)和启用 Python 层的 emacs 24.5.1 中(“层”是一个 spacemacs 概念;请参阅他们的文档),我发现
python-shell-switch-to-shell
打开了一个 IPython 缓冲区。 I tested macropy.console in such a buffer and it works great.我在这样的缓冲区中测试了 macropy.console ,效果很好。
You probably need to have Python in your windows PATH environment variable.您可能需要在 Windows PATH 环境变量中包含 Python。 Can you start the interpreter just by typing
python
in the command window?你可以通过在命令窗口中输入
python
来启动解释器吗?
I don't have anything special in my emacs.el
, but the start interpreter command works just fine.我的
emacs.el
没有什么特别的,但是 start 解释器命令工作得很好。
Also, I recommend reading this blog post , as it contains many useful tips and packages worth installing if using Emacs as a Python IDE.另外,我推荐阅读这篇博文,因为如果使用 Emacs 作为 Python IDE,它包含许多有用的技巧和值得安装的包。
To simply open an interpreter, you can also use Mx python
.要简单地打开解释器,您还可以使用
Mx python
。 If that does not work, try Mx python
and hit TAB, which will list more options via auto-completion.如果这不起作用,请尝试
Mx python
并点击 TAB,它将通过自动完成列出更多选项。 One of them should work k if you have python installed.如果您安装了 python,其中一个应该可以工作。
If you are inclined, it may be worthwhile to check out the Emacs python modes as well - http://www.emacswiki.org/emacs/?action=browse;oldid=PythonMode;id=PythonProgrammingInEmacs如果您愿意,也值得一试 Emacs python 模式 - http://www.emacswiki.org/emacs/?action=browse;oldid=PythonMode;id=PythonProgrammingInEmacs
在 emacs 24.2 中有 python-switch-to-python
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.