【问题标题】:Sublime Text 3 shows EOFError() when I try to run Python scripts with SublimeREPL当我尝试使用 SublimeREPL 运行 Python 脚本时,Sublime Text 3 显示 EOFError()
【发布时间】:2021-05-26 18:09:25
【问题描述】:

当我尝试从 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 控制台,我可以在其中找到错误消息。

【问题讨论】:

  • 这种情况是否发生在任何 Python 脚本或只是特定的脚本中?另外,控制台(Ctrl-`)上是否有任何错误?如果是这样,您可以将它们添加到您的问题中吗?
  • 所有 Python 脚本都会发生这种情况。我检查了控制台并跟进了那里的错误消息。感谢您指出了这一点!我能够从那里解决问题。

标签: python sublimetext3 sublimerepl


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2014-12-19
    • 2016-09-25
    • 1970-01-01
    • 1970-01-01
    • 2015-07-29
    • 1970-01-01
    • 2019-08-28
    • 1970-01-01
    • 2015-05-17
    相关资源
    最近更新 更多