Skip to content Skip to sidebar Skip to footer

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

Solution 1:

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.

Solution 2:

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"; perhaps you can supply it with a custom path?

Post a Comment for "Using Python2.7 With Emacs 24.3 And Python-mode.el"