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"
To start a Python interactive session, just open a command-line or terminal and then type in python , or python3 depending on your Python installation, and then hit Enter .
Step 1: Open the Python IDE and open the script file in Python IDE using the open option given. Or, we can even use the 'F5' button shortcut to run the script file in the Python IDE. That's how we can run or execute our Python script file using the Python IDE installed in our system.
This means that the Python interpreter reads a line of code, executes that line, then repeats this process if there are no errors. The Python Shell gives you a command line interface you can use to specify commands directly to the Python interpreter in an interactive manner.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With