简体   繁体   English

安装 pygame 后出现错误

[英]having errors using pygame after installing it

I've installed pygame Successfully from command prompt and the message was this :我已经从命令提示符成功安装了 pygame,消息是这样的:

Collecting pygame Using cached pygame-2.1.2-cp310-cp310-win_amd64.whl (8.4 MB) Installing collected packages: pygame Successfully installed pygame-2.1.2收集 pygame 使用缓存的 pygame-2.1.2-cp310-cp310-win_amd64.whl (8.4 MB) 安装收集的包:pygame 成功安装 pygame-2.1.2

and when I import pygame in vs code and run the code it doesnt give me an error当我在 vs 代码中导入 pygame 并运行代码时,它不会给我一个错误

my problem is when I write a simple code using pygame it gives me errors我的问题是当我使用 pygame 编写一个简单的代码时,它给了我错误

code:代码:

import pygame

pygame.init()
screen = pygame.display.set_mode((800,400))

and when I run this code it gives me this :当我运行这段代码时,它给了我这个:

Traceback (most recent call last): File "c:\Users\itsae\Documents\Phyton\pygame\pygame.py", line 1, in import pygame File "c:\Users\itsae\Documents\Phyton\pygame\pygame.py", line 3, in pygame.init() AttributeError: partially initialized module 'pygame' has no attribute 'init' (most likely due to a circular import) Traceback(最近一次调用最后):文件“c:\Users\itsae\Documents\Phyton\pygame\pygame.py”,第 1 行,在 import pygame 文件“c:\Users\itsae\Documents\Phyton\pygame\pygame .py",第 3 行,在 pygame.init() AttributeError:部分初始化的模块 'pygame' 没有属性 'init'(很可能是由于循环导入)

my python version : 3.10.4我的python版本:3.10.4

Whats your File Name?你的文件名是什么?

If it's pygame.py rename it to another name如果是 pygame.py 将其重命名为另一个名称

because python recognizes your file is pygame and因为 python 识别你的文件是 pygame 并且

when you give pygame.init() python will check your file for init() function and there is no init() function and it will raise error!当你给 pygame.init() python 会检查你的文件是否有 init() 函数并且没有 init() 函数,它会引发错误!

Try Renaming to another name like PygameFile.py尝试重命名为 PygameFile.py 等其他名称

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM