emacs python3 mode,使用python2.7与Emacs 24.3和python-mode.el

I'm new to Emacs and I'm trying to set up my python environment. So far I've learned that using "python-mode.el" in a python buffer C-c C-c loads the contents of the current buffer into an interactive python shell, apparently using what which python yields. In my case that is 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 C-c C-c. Unfortunatly I can't figure out, how to do this. Setting py-shell-name to what which python2.7 yields (i.e. /usr/bin/python2.7) does not work. How can get Emacs to do this, or how can I trace back what Emacs executes when I hit C-c C-c?

解决方案

python-mode.el, execute a python buffer using python2:

M-x py-execute-buffer-python2

or put this in .emacs file:

(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 C-c C-c key), and if this variable is set to true("t"), then use python interpreter name saved in py-shell-name.

Alternatively, this customization can be done in M-x customize, Programming>Languages>Python Mode, search there for "Py Force Py Shell" and "Py Shell Name" lines.

It will add this customization code to your .emacs file.

Emacs help(describe function):

C-h f py-execute-buffer TAB

You can send selected region in a python buffer to any interpreter:

C-u 3 M-x py-execute-region

Emacs will prompt every time for a python interpreter name you want to use.

The prefix numerical argument may be any number except 1 or 4, otherwise it will use a default interpreter without prompt.

To execute a buffer in different python interpreters you can select whole buffer by C-x h and then use this prefixed command.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值