【问题标题】:ImportError: cannot import name 'my_function' from 'abc'ImportError:无法从“abc”导入名称“my_function”
【发布时间】:2021-03-05 04:53:28
【问题描述】:

试图将 python 脚本从计算机加载到 google colab 但显示 importError

【问题讨论】:

    标签: python-3.x google-colaboratory


    【解决方案1】:

    将文件名 abc.py 更改为其他名称,例如 testo.py,它将起作用。

    from google.colab import files
    
    upload = files.upload()
    
    

    检查!ls

    testo.py

    试试:

    import testo
    
    testo.myfunction()
    
    

    你好世界!

    解释:abc 是一个内置模块,您不应该为您的模块使用该名称。更多info,请查看此问题。

    【讨论】:

      【解决方案2】:

      abc 模块在代码中没有 my_function 类/属性/函数/etc 这是读取 abc 模块的示例转到 python_home/Lib/abc.py 和读取用 C 编写的 _abc 模块转到https://github.com/python/cpython/blob/master/Modules/_abc.c在github

      【讨论】:

        猜你喜欢
        • 2021-03-29
        • 1970-01-01
        • 2022-01-22
        • 2021-06-30
        • 2020-10-19
        • 2018-08-13
        • 2015-01-26
        • 2020-10-10
        • 2020-02-12
        相关资源
        最近更新 更多