Pygame attribute, init()

pygame' has no init member
pygame init error
pygame' has no attribute 'display
partially initialized module 'pygame' has no attribute 'init'
pygame documentation
pygame download
pygame tutorial
no module named 'pygame

I'm trying to use Pygame with Python 3.3 on my windows 8 laptop. Pygame installed fine and when I import pygame it imports fine as well. Although when I try to execute this small code:

import pygame

pygame.init()

size=[700,500]
screen=pygame.display.set_mode(size)

I get this error:

Traceback (most recent call last):
  File "C:\Users\name\documents\python\pygame_example.py", line 3, in <module>
    pygame.init()
AttributeError: 'module' object has no attribute 'init'

I used pygame-1.9.2a0-hg_56e0eadfc267.win32-py3.3 to install Pygame. Pygame is installed in this location 'C:\PythonX' and Python 3.3 is installed in this location 'C:\Python33'. I have looked at other people having the same or similar problem and it doesn't seem to solve the error. Have I done anything wrong when installing Pygame? Or does it not support windows 8?

After import pygame pygame.init()

I got this error message and programm didnt work: " AttributeError: module 'pygame' has no attribute 'init' "

because i named the file "pygame.py"...

When i chaned filename to "pygametest.py" everything worked.

Naming the filename exactly like the modulename seems to confuse python...

AttributeError:module 'pygame' has no attribute 'init', AttributeError:module 'pygame' has no attribute 'init'. Nili. Loading Unsubscribe from Duration: 3:51 Posted: Nov 3, 2019 So after a long time I decided to return to Pygame but immediately after attempting a code run it said: "AttributeError: partially initialized module 'pygame' has no attribute 'init' (most likely due to a circular import)."

You have a directory named pygame in your path somewhere.

$ mkdir pygame  # empty directory
$ python3.3
>>> import pygame
>>> pygame
<module 'pygame' (namespace)>
>>> pygame.__path__
_NamespacePath(['./pygame'])

Remove or rename this directory, it is masking the actual pygame package.

If you use print(pygame.__path__) it'll tell you where the directory was found; in the above example it was found relative to the current directory (./).

AttributeError: partially initialized module 'pygame' has no , When run "pygame.init()"in the interactive line, it works. But when run a .py file, following error happens: Traceback (most recent  pygame.init() initializes the pygame module, you don't assign it as a variable.

I also named my app pygame.py and i had the same issue but when i changed it, it worked for me .

Pygame.init(), pygame,init(). it give me the following error: AttributeError: partially initialized module 'pygame' has no attribute 'init' (most likely due to a circular  Pylint imports modules to effectively identify valid methods and attributes. It was decided that importing c extensions that are not part of the python stdlib is a security risk and could introduce malicious code. and as a solution it mentions, among others: Disable safety using the.pylintrc setting unsafe-load-any-extensions=yes.

What exactly does pygame.init() do?, You can always initialize individual modules manually, but pygame.init() initialize all imported New in pygame 1.9.6: Attributes major , minor , and patch . 2d 721 pygame 670 arcade 665 game 339 puzzle 270 shooter 247 python 212 strategy 178 action 156 libraries 148 space 142 other 138 multiplayer 121 platformer 119 rpg 113 simple 100 applications 90 retro 82 gpl 82 3d 75 pyopengl 73 pyweek 70 geometrian 67 snake 65 library 63 physics 55 engine 55 gui 53 simulation 49 josmiley 45 ALL the tags!

3.6: The QUIT Event and pygame.quit() Function, This scenario is described in this StackOverflow: Pygame attribute, init() thread. Apparently it's partially triggered (in the case of a directory named pygame with  init() -> (numpass, numfail) Initialize all imported pygame modules. module fails, but the total number if successful and failed inits will be returned as a tuple. You can always initialize individual modules manually,

pygame.display, the command prompt said: "File "C:\Users\kacper\pygame.py", line 3, in <​module> pygame.init() AttributeError: module 'pygame' has no attribute 'init'" does​  after the display modules have initialized. The top level pygame.init()takes care of this automatically, but cannot pass any arguments to the mixer init. To solve this, mixer has a function pygame.mixer.pre_init()to set the proper defaults before the toplevel init is used. When using allowedchanges=0 it will convert the samples at runtime to match

Comments
  • What does import pygame; print(pygame.__file__) print?
  • Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> print(pygame.__file__) AttributeError: 'module' object has no attribute 'file' @MartijnPieters
  • Interesting. No idea what you imported there, but I am trying to figure out if that is actually the pygame module or something else. It is certainly possible that the 'real' pygame module has no .__file__ attribute, but it is surprising. Does print(pygame) give any detail?
  • Also, I want you to add the print() statements to your script, not run them in a Python shell please.
  • When I printed print(pygame.__file__) in my script I still got the same error as before and when I printed print(game) in my script I got this: <module 'pygame' (namespace)>. @MartijnPieters
  • @interjay: No, not in Python 3, which added namespace support (what setuptools does with special __init__.py files).
  • I see. I guess the documentation is outdated then because it says: "The __init__.py files are required to make Python treat the directories as containing packages; this is done to prevent directories with a common name, such as string, from unintentionally hiding valid modules that occur later on the module search path."
  • @interjay: these are not packages. These are namespaces. :-P
  • @interjay: but if you feel that the tutorial is now no longer correct, do feel free to file a bug with the Python project.
  • btw: You can get the same error if you put your code in file pygame.py