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

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*

```

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.

Answer: 
regarding jrockway's comment:

```
(defun is-python3-p () "Check whether we're running python 2 or 3."
  (setq mystr (first (split-string (buffer-string) "\n" t)))
  (with-temp-buffer
    (insert mystr)
    (goto-char 0)
    (search-forward "python3" nil t)))
(defun run-python () "Call the python interpreter."
  (interactive)
  (if (is-python3-p)
      (setq py-python-command "/usr/bin/python3")
    (setq py-python-command "/usr/bin/python"))
  (py-execute-buffer))

```

This will call `python3` if "python3" is in the top line of your buffer (shebang, usually). For some reason the `(setq py-pyton-command ...)` doesn't let you change versions once you've run `py-execute-buffer` once. That shouldn't be an issue unless you change your file on the same buffer back and forth.
With current `python-mode.el` shebang is honored.

Interactively open a Python shell just with

```
M-x pythonVERSION    
M-x python

```

will call the installed default.

<http://launchpad.net/python-mode>