Python Forum
[PyGame] Apparently module has no attribute display?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGame] Apparently module has no attribute display?
#1
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'
Reply
#2
you have to do
pygame.init()
after importing and before creating your screen
Recommended Tutorials:
Reply
#3
Doing that makes it say that module has no attribute init()
Reply
#4
did you name your file pygame.py?
Recommended Tutorials:
Reply
#5
No, I named it pygametesteroo.py
Reply
#6
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))
99 percent of computer problems exists between chair and keyboard.
Reply
#7
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?
Reply
#8
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'])
99 percent of computer problems exists between chair and keyboard.
Reply
#9
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
Reply
#10
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'>
99 percent of computer problems exists between chair and keyboard.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] Apparently module has no attribute display? Angelo26 1 1,969 Mar-11-2020, 07:14 PM
Last Post: nilamo
  [split] Apparently module has no attribute display? Kolterdyx 1 2,788 Sep-09-2018, 05:14 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020