Python Forum
[PyGame] Apparently module has no attribute display? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Game Development (https://python-forum.io/forum-11.html)
+--- Thread: [PyGame] Apparently module has no attribute display? (/thread-7000.html)

Pages: 1 2 3


Apparently module has no attribute display? - Klar - Dec-17-2017

Hey, it's me again! I have no experience with PyGame at all!
Anyway, I'm importing this code:
import pygame

screen = pygame.display.set_mode((640, 400))

running = 1

while running:
	event = pygame.event.poll()
	if event.type == pygame.quit:
		running = 0
and it returns
Error:
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\[path]\pygametesteroo.py", line 3, in <module> screen = pygame.display.set_mode((640, 400)) AttributeError: 'module' object has no attribute 'display'



RE: Apparently module has no attribute display? - metulburr - Dec-17-2017

you have to do
pygame.init()
after importing and before creating your screen


RE: Apparently module has no attribute display? - Klar - Dec-17-2017

Doing that makes it say that module has no attribute init()


RE: Apparently module has no attribute display? - metulburr - Dec-17-2017

did you name your file pygame.py?


RE: Apparently module has no attribute display? - Klar - Dec-17-2017

No, I named it pygametesteroo.py


RE: Apparently module has no attribute display? - Windspar - Dec-17-2017

Did you call one of your programs pygame.py ?
Because it will try to import from that over pygame site package.

If not. Maybe some info will help.
import sys
import pygame
print(pygame.version)
print(sys.version)

This will print alot of data. about 1 to 2 terminal pages worth.
print(dir(pygame))



RE: Apparently module has no attribute display? - Klar - Dec-17-2017

breath
MODULE HAS NO ATTRIBUTE VERSION
dir(pygame) just prints the same as dir()
I don't what's happening. I've tried uninstalling it multiple times. It installs the wheel version even after I delete it. Huh?


RE: Apparently module has no attribute display? - Windspar - Dec-17-2017

It doesn't sound like it the package. It sound like you have another file name pygame.py which it importing from. I would just run a search. Searching for all pygame.py. There should only should be one. Unless you install multiple pythons with pygame.

If you name a file pygame.py for a test program. It would cause the problems in your pygametesteroo.py.

you can use os search or
import os

def main():
	your_root_folder = 'replace with root name'
	for dirpath, dirnames, filenames in os.walk(your_root_folder):
		for fname in filenames:
			if fname == 'pygame.py':
				print(os.path.join(dirpath, fname))
	
main()

Try this first and give output. Block out personal info in path with .. , my linux path '/home/../programming/pygame.py'.
import pygame
print(locals()['pygame'])



RE: Apparently module has no attribute display? - Klar - Dec-17-2017

All I've found with the search (not the ones you suggested since I use windows, not linux) have lead me to a folder named pygame, followed by a folder name __pycache__, followed by the .pyc for the .init


RE: Apparently module has no attribute display? - Windspar - Dec-17-2017

You might want to uninstall pygame. Cleanup and folders left behind. Then reinstall.

Still like to see where it is import from.
import pygame
print(locals()['pygame'])
My output. Since you are using windows. I would expect something like 'c:/program files/python3.6/etc'
Output:
<module 'pygame' from '/usr/lib/python3.6/site-packages/pygame-1.9.3-py3.6-linux-x86_64.egg/pygame/__init__.py'>