【发布时间】:2016-02-17 00:19:35
【问题描述】:
我在 OS X (El Capitan) 上使用 Python 劣质外壳,每次我向 Python 进程发送一段代码(使用绑定到 python-shell-send-region 的 C-c C-r)时,我都会收到这样的消息Python 外壳:
>>> 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 安装)。我在.emacs 中使用的唯一 python 模式特定配置与选项卡宽度有关:
(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。
【问题讨论】:
-
我找到了解决这个烦恼的方法。
ipython对我来说似乎没有同样的问题。您可以将python-shell-interpreter设置为 ipython(.emacs中的类似内容):(setq python-shell-interpreter "ipython2") -
该解决方案(issues/1307)对我有用,只需稍作改动。
easy_install-3.6 => pip3 install3.6 => 3.736m => 37m
标签: python macos emacs python.el comint-mode