Pygame pygame.init() error " module 'pygame' has no attribute 'init' "

My python code shows this error: module ‘pygame’ has no attribute ‘init’
I’ve heard that it’s caused by circular import my my file name isnt “python.py?”


This is my current code

What does print(pygame.__file__) result in?

It prints “None”

That means you have a folder called pygame somewhere, which gets turned into a namespace package. You can call pygame.__path__ to check where that folder is.

Also, how did you install pygame? Are you sure you are running the correct python?

1 Like

I installed pygame-ce using the terminal on mac
Also, the path sends me this _NamespacePath([‘/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pygame’])

I feel I should point out that this code worked perfectly fine a day ago

Can you try reinstalling pygame-ce? Also, make sure you only have exactly one between pygame and pygame-ce installed. Check pip list.

Essentially there should be a __init__.py file in that folder, but for some reason it’s missing.

maybe its because i installed both and then uninstalled pygame?

Thank you :') I probably wouldn’t have figured it out

Aha yep, that will do it. pip is stupid in this regard: it doesn’t check for conflicting files nor can it know which install package actually provided a file, meaning that a file will always be removed if it was provided by two install packages separately when either is uninstalled.

1 Like