没有任何描述性线索的错误消息似乎模棱两可

Error message seems ambiguous without any descriptive clue

我是 transcrypt 的新手。我创建了一个测试 python 文件,test.py

def test_def(a: list):      
    for i in range(len(a)):
        print(i)

xx = [2, 3, 4]
test_def(xx)

我有 python 3.9。如果我 运行 python 文件,它会 运行 并按预期打印。

运行 transcrypt 给出以下错误

> python -m transcrypt -b -m -n .\test.py
Error while compiling (offending file last):
        File 'test', line 2, namely:

        Error while compiling (offending file last):
        File 'test', line 2, namely:


Aborted

我不确定它期望什么以及为什么会出现错误,我们将不胜感激。

您使用的是哪个版本的 Transcrypt?无法使用 Python 3.9.0 和 Transcrypt 3.9.0 复制错误。你可以这样检查 (Win):

> transcrypt -h | find "Version"
# and may as well double check that the right version of python was used:
> python --version

Python 和 Transcrypt 版本应该匹配,因为 Transcrypt 使用 Python 的 AST,可能会在不同版本之间发生变化。

另一个方面是我首先将 Transcrypt 安装到虚拟环境中,如下所示 (Win):

> py -3.9 -m venv wenv
> wenv\Source\activate.bat
> pip install transcrypt
> python -m transcrypt -b -m -n test.py

有时会发生不小心使用错误版本的 Python。 'py' 是 Windows 上的 Python 启动器,如果您安装了多个版本,它有助于启动正确的版本。在 Linux 上通常有 /usr/bin 中的二进制文件,例如 'python3.9' 或链接到最新 3 版本的符号链接,例如 'python3'。如所示安装到虚拟环境中也很有帮助,否则可能会出现各种问题。

以上编译test.py没有报错(Win 10cmd.exe)。 Fwiw,该文件被保存为 utf-8 并且可以在有和没有 BOM 的情况下进行编译。