6

What does it take to replace regular /usr/bin/python with a custom python shell in Emacs' python-mode?

Basically I have a binary /usr/bin/mypython which does some initializations before starting python interpreter prompt, and for all interaction purposes, the resulting interpreter shell is equivalent to /usr/bin/python.

However, if I specify this binary in "python-python-command" (using python.el in Emacs 23.3), I get "Only Python versions >=2.2 and < 3.0 are supported"

3 Answers 3

5

I'm about to read the elisp to check, but I'd bet if you added a --version flag that gave the save results as /usr/bin/python, emacs would be happy.

Update

Here's the code in python.el line 1555 et seq in EMACS 23.3.1:

(defvar python-version-checked nil)
(defun python-check-version (cmd)
  "Check that CMD runs a suitable version of Python."
  ;; Fixme:  Check on Jython.
  (unless (or python-version-checked
          (equal 0 (string-match (regexp-quote python-python-command)
                     cmd)))
    (unless (shell-command-to-string cmd)
      (error "Can't run Python command `%s'" cmd))
    (let* ((res (shell-command-to-string
                 (concat cmd
                         " -c \"from sys import version_info;\
print version_info >= (2, 2) and version_info < (3, 0)\""))))
      (unless (string-match "True" res)
    (error "Only Python versions >= 2.2 and < 3.0 are supported")))
    (setq python-version-checked t)))

What it's doing is running a one-liner

from sys import version_info;
print version_info >= (2, 2) and version_info < (3, 0)

that just prints "True" or "False". Fix your script to handle the -c flag and you should be fine.

Alternatively, you could take the hacker's way out and force the value of python-version-checked to t, and it'll never do the check.

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

2 Comments

Thanks for the pointer, looking through file I found another problem -- "-i" flag is hardwired (so removing it from python-python-command-args will not prevent it from being passed)
Well, that's why they give you the sources. But that, in particular, sounds like a bug to me; change it and submit a patch.
1

The easiest way to defeat the check is to lie and tell python-check-version that it's already checked:

(setq python-version-checked t)

Comments

0

with python-mode.el just do

M-x MY-PYTHON RET

given the Python version is installed

https://launchpad.net/python-mode

1 Comment

Welcome to StackOverflow! I see that you are enthusiastic and have a favorite tool. However, recommending or linking to the same site in all your posts, and 10 times during your first day alone, risks triggering the "potential spam" signals on this site. So take care! Just a friendly advice.

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.