在Emacs的python模式下,用自定义的python shell替换常规的/usr/bin/python需要什么?
基本上,我有一个二进制文件/usr/bin/mypython,它在启动python解释器提示符之前执行一些初始化,并且出于所有交互目的,最终得到的解释器shell等同于/usr/bin/python。
但是,如果我在" Python -python-command“中指定这个二进制文件(在Emacs23.3中使用python.el ),我会得到”只支持Python版本>=2.2和< 3.0“。
发布于 2011-06-08 09:48:54
我即将读取elisp进行检查,但我敢打赌,如果您添加了一个将保存结果指定为/usr/bin/python的--version标志,emacs会很高兴的。
更新
以下是EMACS 23.3.1中python.el行1555 et seq中的代码:
(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)))它所做的就是运行一行程序
from sys import version_info;
print version_info >= (2, 2) and version_info < (3, 0)这只会打印"True“或"False”。修复您的脚本以处理-c标志,您就应该没问题了。
或者,您可以采取黑客的方式,并强制将python-version-checked的值设置为t,但它永远不会执行检查。
发布于 2011-06-08 09:57:22
让检查失败的最简单的方法是撒谎,告诉python-check-version它已经检查过了:
(setq python-version-checked t)发布于 2012-07-23 02:51:40
https://stackoverflow.com/questions/6273329
复制相似问题