2

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?

1
  • I think you may need something like this, which I use for latex: (setenv "PATH" (concat (getenv "PATH") ":/usr/texbin")) -- of course, you would place your own path to your python stuff instead. Commented Feb 6, 2014 at 0:39

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.