解决module 'pygame' has no attribute 'init'

运行python文件出现 has no attribute ‘init’ 这个情况

import pygame
pygame.init()
pygame.display.set_mode()
pygame.quit()


按视频的内容练习pygame的时候出现AttributeError: module 'pygame' has no attribute 'init'这个情况
但是在powershell导入是可以正常使用的
pygame可以看到导入文件正确路径


在报错中查看跟路径是不对的,到报错路径中查看有个pygame的文件


顿时明白了,是当时命名文件的时候顺手就把pygame弄成pygame.py了,随意出现这个问题,相当于递归了
python在导入包的时候他是先查找当前路径有没有这个包,然后在一级一级往外边查找,找到文件名一致的,就会导进去,所以在命名的时候要注意,不要犯这种低级错误

猜你喜欢

转载自blog.csdn.net/dhshttgb/article/details/85258181