一、报错展示

红框的内容会根据import的包的名字发生变化

报错(AttributeError: module 'xxx' has no attribute 'connect')的解决办法

二、报错原因(测试的包为pymysql,其他包同理)

  1. 原因一(大多数情况):

    import的包名与文件名相同

    报错(AttributeError: module 'xxx' has no attribute 'connect')的解决办法

  2. 原因二(少数情况):

    文件名与其他包冲突

    可以看到下图中并没有异常,但是报错了报错(AttributeError: module 'xxx' has no attribute 'connect')的解决办法

    这是什么原因导致的呢,点击一下报错内容报错(AttributeError: module 'xxx' has no attribute 'connect')的解决办法
    这回就明白了,文件名与其他包冲突了报错(AttributeError: module 'xxx' has no attribute 'connect')的解决办法

三、解决办法

目前发现的解决办法只有换文件名了,如果有其他办法,欢迎留言补充

相关文章: