Emacs 中的 Python 2 和 3 [英] Both Python 2 and 3 in Emacs

查看:25
本文介绍了Emacs 中的 Python 2 和 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 Emacs 编写 Python 2 代码.现在我的系统上安装了 Python 2.6 和 3.0,我还需要编写 Python 3 代码.

I have been using Emacs to write Python 2 code. Now I have both Python 2.6 and 3.0 installed on my system, and I need to write Python 3 code as well.

以下是在/usr/bin 中设置不同版本的方式:

Here is how the different versions are set up in /usr/bin:

python -> python2.6*
python2 -> python2.6*
python2.6*

python3 -> python3.0*
python3.0*

有什么方法可以设置,以便 Emacs 使用正确版本的 Python,具体取决于我使用的语言?例如,C-c C-c 当前运行缓冲区,但它始终调用 python2.6,即使我正在编写 Python 3 代码.

Is there any way to set this up so that Emacs uses the correct version of Python, depending on which language I am using? For instance, C-c C-c currently runs the buffer, but it always calls python2.6, even if I am writing Python 3 code.

推荐答案

如果您使用的是 python-mode.el,您可以尝试更改 py-which-shell.为了在每个文件的基础上执行此操作,您可以将

If you are using python-mode.el you can try to change py-which-shell. In order to do this on a per-file basis you can put

# -*- py-which-shell: "python3"; -*-

在文件的第一行 - 如果第一行以 #! 开头,则在第二行.另一种选择是把

at the first line of your file - or at the second line if the first line starts with #!. Another choice is to put

# Local Variables:
# py-which-shell: "python3" 
# End: 

在文件的末尾.也许您应该提供 python3 的完整路径,而不仅仅是python3".

at the end of your file. Perhaps you should give the full path to python3 instead of just "python3".

这篇关于Emacs 中的 Python 2 和 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆