You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除Emacs中使用run-python时出现的__PYTHON_EL_eval消息?

解决Emacs run-python输出附带__PYTHON_EL_eval(...)前缀的问题

以下是几种可行的解决方法:

  • 自定义输出过滤函数:通过添加输出过滤规则,自动移除前缀内容。将以下代码添加到你的Emacs配置文件(如~/.emacs或~/.emacs.d/init.el)中:

    (defun python-filter-eval-prefix (output)
      ;; 匹配开头的__PYTHON_EL_eval(...) 前缀并移除
      (replace-regexp-in-string "^__PYTHON_EL_eval(.*?) " "" output))
    
    (add-hook 'python-shell-filter-regexp-functions #'python-filter-eval-prefix)
    

    添加后重启Emacs,或执行M-x eval-buffer让配置生效,后续run-python的输出就会自动过滤掉前缀。

  • 替换默认的代码执行函数:修改python-shell-eval-function,改用不输出前缀的方式执行代码。配置代码如下:

    (setq python-shell-eval-function
          (lambda (string)
            (python-shell-send-string string)
            nil))
    

    这个方法直接改变了Emacs向Python进程发送代码的方式,避免触发前缀消息的输出。

  • 升级相关组件:如果使用的是较旧版本的Emacs或python-mode,这个问题可能是已知的bug,升级到最新版的Emacs或python-mode包,大概率能直接解决该问题。

内容的提问来源于stack exchange,提问作者tomas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 22:10:35