我在 OS X (El Capitan) 上使用 Python 劣质 shell,每次我向 Python 进程发送一段代码(使用C-c C-r
绑定到python-shell-send-region
)时,我都会在 Python shell 中收到如下消息:
>>> import codecs, os;
__pyfile = codecs.open('''/var/folders/6j/g9hcs1s17g1dgxr3p_m04rq80000gn/T/py5013kfY''', encoding='''utf-8''');
__code = __pyfile.read().encode('''utf-8''');
__pyfile.close();
os.remove('''/var/folders/6j/g9hcs1s17g1dgxr3p_m04rq80000gn/T/py5013kfY''');
exec(compile(__code, '''/Users/user/Desktop/sample.py''', 'exec'));
我不希望每次调用命令时都显示此消息。Linux 上相同版本的 Emacs(连同 python.el 文件)没有这个问题。消息的模板是在python-shell-send-file
函数(在python.el
文件中)中定义的,这本身就令人费解,因为我看不到在调用python-shell-send-region
. 对于第一次运行,我使用以下命令调用 Python 解释器(版本 2.7.10)
/usr/bin/python -i
但它与其他 python 解释器(通过 brew 安装)的行为也相同。我正在使用 Emacs 24.5.1(再次通过 brew 安装)。我使用的唯一 python 模式特定配置.emacs
与选项卡宽度有关:
(add-hook 'python-mode-hook
(lambda ()
(setq indent-tabs-mode t)
(setq tab-width 2)
(setq python-indent 2)))
任何帮助或建议表示赞赏。
编辑和可能的解决方案:
(我发现这个https://github.com/jorgenschaefer/elpy/issues/1307):
$ easy_install-3.6 gnureadline
$ cd /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload
$ mv readline.cpython-36m-darwin.so readline.cpython-36m-darwin.so.bak
如果您在安装 gnureadline 时遇到错误,请fatal error: 'stdio.h' file not found
尝试xcode-select --install
.