如何使打字机回溯看起来正常

Cor*_*mer 5 python command-line-interface traceback typer

当使用typer解析 CLI 参数时,我收到非常详细且丰富多彩的错误消息。如何获得正常的 Python 回溯?

\n

请参阅示例回溯的屏幕截图(仅前几行)以了解详细样式的说明:

\n
\xe2\x9d\xaf python scripts/add_priors.py             \n\xe2\x95\xad\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80 Traceback (most recent call last) \xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x95\xae\n\xe2\x94\x82 /Users/corneliusromer/code/nextclade_data_workflows/sars-cov-2/scripts/add_priors.py:26 in main  \xe2\x94\x82\n\xe2\x94\x82                                                                                                  \xe2\x94\x82\n\xe2\x94\x82   23 \xe2\x94\x82   import polars as pl                                                                     \xe2\x94\x82\n\xe2\x94\x82   24 \xe2\x94\x82                                                                                           \xe2\x94\x82\n\xe2\x94\x82   25 \xe2\x94\x82   priors = (                                                                              \xe2\x94\x82\n\xe2\x94\x82 \xe2\x9d\xb1 26 \xe2\x94\x82   \xe2\x94\x82   pl.scan_ndjson(ndjson, infer_schema_length=10000)                                   \xe2\x94\x82\n\xe2\x94\x82   27 \xe2\x94\x82   \xe2\x94\x82   .select(                                                                            \xe2\x94\x82\n\xe2\x94\x82   28 \xe2\x94\x82   \xe2\x94\x82   \xe2\x94\x82   [                                                                               \xe2\x94\x82\n\xe2\x94\x82   29 \xe2\x94\x82   \xe2\x94\x82   \xe2\x94\x82   \xe2\x94\x82   pl.col("nearestNodes"),                                                     \xe2\x94\x82\n\xe2\x94\x82                                                                                                  \xe2\x94\x82\n\xe2\x94\x82 \xe2\x95\xad\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80 locals \xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x95\xae \xe2\x94\x82\n\xe2\x94\x82 \xe2\x94\x82   json = <module \'json\' from                                                                 \xe2\x94\x82 \xe2\x94\x82\n\xe2\x94\x82 \xe2\x94\x82          \n
Run Code Online (Sandbox Code Playgroud)\n

Cor*_*mer 3

您可以通过设置环境变量一次性禁用它_TYPER_STANDARD_TRACEBACK=1

pretty_exceptions_enable=False通过在初始化时传递 kwarg 可以禁用丰富的异常typer

import typer

app = typer.Typer(pretty_exceptions_enable=False)

@app.command()
def main():
    raise Exception("test")

if __name__ == "__main__":
    app()
Run Code Online (Sandbox Code Playgroud)

请参阅文档了解更多选项