1

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

2
  • 1
    This is because your file, the one you are executing(that has all your game code), itself is named with the same name as the pygame module. This results in python failing to import the real pygame module, as it looks for the module name in the same directory as the file being executed first, and so it imports the file being executed as the module itself, and thus it errors out mentioning about the circular import. Commented May 12, 2022 at 6:51
  • @typedecker yep that was my problem , thanks :) Commented May 12, 2022 at 7:14

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

3 Comments

This could have been a comment as well, there was no need to write it as an answer as it does not answer/solve the problem.(Written for the original solution, eventhough even the current solution, seems to reflect the answerer's improper reading of the OP).
I'm a new to Stack Over Flow so i don't have privilege to comment
I hope this helps, and I am sorry for the previous comment, well I should've realized that new contributors don't have the comment privilege.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.