You need to enable JavaScript to run this app. Sublime Text 3使用SublimeREPL运行Python脚本报错EOFError()如何解决?
优惠活动
大模型
产品
解决方案
定价
更多

Sublime Text 3使用SublimeREPL运行Python脚本报错EOFError()如何解决?

Sublime Text 3 配合 SublimeREPL 运行 Python 脚本报 EOFError() 问题解决方案

问题表现

  • 在 Sublime Text 3 中通过 SublimeREPL 运行 Python 脚本时,仅弹出显示EOFError()的对话框,无其他额外提示
  • 此前已修改 SublimeREPL 配置文件 C:\Users\Al\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\config\Python\Main.sublime-menu,给 Python 解释器添加-i命令行参数,实现脚本运行结束后保留交互式 shell 的效果,该配置此前一直可以正常使用

原配置文件内容

[
     {
        "id": "tools",
        "children":
        [{
            "caption": "SublimeREPL",
            "mnemonic": "R",
            "id": "SublimeREPL",
            "children":
            [
                {"caption": "Python",
                "id": "Python",

                 "children":[
                    {"command": "repl_open",
                     "caption": "Python",
                     "id": "repl_python",
                     "mnemonic": "P",
                     "args": {
                        "type": "subprocess",
                        "encoding": "utf8",
                        "cmd": ["python", "-i", "-u"],
                        "cwd": "$file_path",
                        "syntax": "Packages/Python/Python.tmLanguage",
                        "external_id": "python",
                        "extend_env": {"PYTHONIOENCODING": "utf-8"}
                        }
                    },
                    {"command": "python_virtualenv_repl",
                     "id": "python_virtualenv_repl",
                     "caption": "Python - virtualenv"},
                    {"command": "repl_open",
                     "caption": "Python - PDB current file",
                     "id": "repl_python_pdb",
                     "mnemonic": "D",
                     "args": {
                        "type": "subprocess",
                        "encoding": "utf8",
                        "cmd": ["python", "-i", "-u", "-m", "pdb", "$file_basename"],
                        "cwd": "$file_path",
                        "syntax": "Packages/Python/Python.tmLanguage",
                        "external_id": "python",
                        "extend_env": {"PYTHONIOENCODING": "utf-8"}
                        }
                    },
                    {"command": "repl_open",
                     "caption": "Python - RUN current file",
                     "id": "repl_python_run",
                     "mnemonic": "R",
                     "args": {
                        "type": "subprocess",
                        "encoding": "utf8",
                        "cmd": ["python", "-i", "-u", "$file_basename"],
                        "cwd": "$file_path",
                        "syntax": "Packages/Python/Python.tmLanguage",
                        "external_id": "python",
                        "extend_env": {"PYTHONIOENCODING": "utf-8"}
                        }
                    },
                    {"command": "repl_open",
                     "caption": "Python - IPython",
                     "id": "repl_python_ipython",
                     "mnemonic": "I",
                     "args": {
                        "type": "subprocess",
                        "encoding": "utf8",
                        "autocomplete_server": true,
                        "cmd": {
                            "osx": ["python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
                            "linux": ["python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"],
                            "windows": ["python", "-u", "${packages}/SublimeREPL/config/Python/ipy_repl.py"]
                        },
                        "cwd": "$file_path",
                        "syntax": "Packages/Python/Python.tmLanguage",
                        "external_id": "python",
                        "extend_env": {
                            "PYTHONIOENCODING": "utf-8",
                            "SUBLIMEREPL_EDITOR": "$editor"
                        }
                    }
                    }
                ]}
            ]
        }]
    }
]

报错信息

查看 Sublime Text 控制台,运行脚本后输出如下错误栈:

Traceback (most recent call last):
  File "C:\Users\Al\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\sublimerepl.py", line 495, in open
    rv = ReplView(view, r, syntax, repl_restart_args)
  File "C:\Users\Al\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\sublimerepl.py", line 186, in __init__
    self._history = PersistentHistory(self.external_id)
  File "C:\Users\Al\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\sublimerepl.py", line 140, in __init__
    self._db.create("external_id", "command", "ts", mode="open")
  File "C:\Users\Al\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\repllibs\PyDbLite.py", line 193, in create
    return self.open()
  File "C:\Users\Al\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\repllibs\PyDbLite.py", line 246, in open
    self.fields = pickle.load(_in)
EOFError
error: EOFError()

问题根因

卸载重装 SublimeREPL 后重启 Sublime Text 问题仍然存在,经排查确认错误触发原因是:SublimeREPL 存储 Python 命令历史的文件 C:\Users\Al\AppData\Roaming\Sublime Text 3\Packages\User\.SublimeREPLHistory\python.db 损坏,文件被意外写入空字符,导致插件读取历史记录时触发 EOF 错误。

解决方法

  • 先备份上述路径下的python.db文件,再将原文件删除
  • 重启 Sublime Text 即可恢复正常,插件会自动生成新的空白历史文件

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.18 23:36:08