简体   繁体   English

在Emacs 24.3和python-mode.el中使用python2.7

[英]Using python2.7 with Emacs 24.3 and python-mode.el

I'm new to Emacs and I'm trying to set up my python environment. 我是Emacs的新手,正在尝试设置python环境。 So far I've learned that using "python-mode.el" in a python buffer Cc Cc loads the contents of the current buffer into an interactive python shell, apparently using what which python yields. 到目前为止,我已经了解到在python缓冲区中使用“ python-mode.el” Cc Cc将当前缓冲区的内容加载到交互式python shell中,显然使用的是which python产生的结果。 In my case that is python 3.3.3. 在我的情况下是python 3.3.3。 But since I need to get a python 2.7 shell, I'm trying to get Emacs to spawn such a shell on Cc Cc . 但是由于我需要一个python 2.7 shell,所以我试图让Emacs在Cc Cc上生成这样的shell。 Unfortunatly I can't figure out, how to do this. 不幸的是,我不知道该怎么做。 Setting py-shell-name to what which python2.7 yields (ie /usr/bin/python2.7 ) does not work. py-shell-name设置为which python2.7产生的结果(即/usr/bin/python2.7 )不起作用。 How can get Emacs to do this, or how can I trace back what Emacs executes when I hit Cc Cc ? 如何使Emacs做到这一点,或者当我点击Cc Cc时如何追溯Emacs执行的操作?

python-mode.el, execute a python buffer using python2: python-mode.el,使用python2执行python缓冲区:

Mx py-execute-buffer-python2

or put this in .emacs file: 或将其放在.emacs文件中:

(custom-set-variables
    '(py-force-py-shell-name-p t)
    '(py-shell-name "python2"))

python-mode.el checks py-force-py-shell-name-p variable when executing py-execute-buffer (bound to Cc Cc key), and if this variable is set to true("t"), then use python interpreter name saved in py-shell-name . python-mode.el在执行py-execute-buffer (绑定到Cc Cc键)时检查py-force-py-shell-name-p变量,如果此变量设置为true(“ t”),则使用python解释器名称保存在py-shell-name

Alternatively, this customization can be done in Mx customize , Programming>Languages>Python Mode, search there for "Py Force Py Shell" and "Py Shell Name" lines. 或者,可以在Mx customize ,编程>语言> Python模式下进行此自Mx customize ,在此处搜索“ Py Force Py Shell”和“ Py Shell Name”行。 It will add this customization code to your .emacs file. 它将将此自定义代码添加到您的.emacs文件中。

Emacs help(describe function): Emacs帮助(描述功能):

Ch f py-execute-buffer TAB

You can send selected region in a python buffer to any interpreter: 您可以将python缓冲区中的选定区域发送给任何解释器:

Cu 3 Mx py-execute-region

Emacs will prompt every time for a python interpreter name you want to use. Emacs每次都会提示您要使用的python解释器名称。 The prefix numerical argument may be any number except 1 or 4, otherwise it will use a default interpreter without prompt. 前缀数字参数可以是1或4以外的任何数字,否则它将使用默认解释器,而不会出现提示。

To execute a buffer in different python interpreters you can select whole buffer by Cx h and then use this prefixed command. 要在不同的python解释器中执行缓冲区,您可以按Cx h选择整个缓冲区,然后使用此前缀命令。

I don't use python, but from the source to python-mode, I think you should look into customizing the variable python-python-command - It seems to default to the first path command matching "python"; 我不使用python,但是从源代码到python-mode,我认为您应该研究自定义变量python-python-command似乎默认为匹配“ python”的第一个路径命令; perhaps you can supply it with a custom path? 也许您可以为其提供自定义路径?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM