简体   繁体   中英

having errors using pygame after installing it

I've installed pygame Successfully from command prompt and the message was this :

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

and when I import pygame in vs code and run the code it doesnt give me an error

my problem is when I write a simple code using pygame it gives me errors

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)

my python version : 3.10.4

Whats your File Name?

If it's pygame.py rename it to another name

because python recognizes your file is pygame and

when you give pygame.init() python will check your file for init() function and there is no init() function and it will raise error!

Try Renaming to another name like PygameFile.py

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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