当我尝试使用 SublimeREPL 运行 Python 脚本时,Sublime Text 3 显示 EOFError()

Sublime Text 3 shows EOFError() when I try to run Python scripts with SublimeREPL

当我尝试 运行 来自 Sublime Text 3 的 Python 脚本时,我得到一个弹出对话框,仅显示“EOFError()”,仅此而已。

我正在使用 SublimeREPL 插件,对我的 C:\Users\Al\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\config\Python\Main.sublime-menu 文件(基于此视频:https://www.youtube.com/watch?v=wM2LbXCkLDI)进行了一些细微的修改,因此我可以在其中打开交互式 shell 运行 程序的单独选项卡。我所做的主要更改是在脚本完成后将 Python 解释器的“-i”命令行参数添加到 运行 交互式 shell。

这以前工作得很好。我不确定我的配置或 Python 或 SublimeREPL 包发生了什么变化以使其不再工作。

这是我的 Main.sublime-menu 文件:

[
     {
        "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 控制台时,它在我尝试 运行 一个 Python 脚本后显示此错误:

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,但我收到相同的错误消息。

我调试了一下,发现_inC:\Users\Al\AppData\Roaming\Sublime Text 3\Packages\User\.SublimeREPLHistory\python.db的一个文件对象,一个819kb的文件。我尝试删除它(先将其备份到另一个文件夹)并重新启动 Sublime Text。这似乎奏效了!我想不知何故一些空字符被写入了历史文件?现在可以了。感谢 MattDMo 将我指向 Sublime Text 控制台,在那里我可以找到错误消息。

我通过删除 C:\Users\Al\AppData\Roaming\Sublime Text 3\Packages\User\.SublimeREPLHistory\python.db(尽管它会根据您的用户名位于不同的文件夹中)并重新启动 Sublime Text 自行解决了这个问题。

我猜有些空字符被写入了历史文件?现在可以了。感谢 MattDMo 将我指向 Sublime Text 控制台,在那里我可以找到错误消息。