如何使用内置python库修复导入错误?

问题描述 投票:0回答:1

我在将python统计信息库导入程序时遇到问题。每当我在顶部写import statistics并尝试运行代码时,都会给我一个导入错误:“没有名为统计信息的模块”。

我在virtualenv内部使用python 3.8,并使用终端检查了python版本。我将崇高文字用作代码编辑器。

我也尝试导入随机库,它可以正常工作。

python statistics importerror
1个回答
0
投票

对于导入错误,您可以使用“ try”来捕获该错误并打印一条消息,如果发生错误,请采取其他措施:

try:
    import some_module_not_exist
except Exception as error:
    pritn(error)
    # DO some things

替换代码上原始代码的常规异常。

© www.soinside.com 2019 - 2024. All rights reserved.