Hello guest, if you read this it means you are not registered. Click here to register in a few simple steps, you will enjoy all features of our Forum.
Bottom Page

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'
Quote
#2
you have to do
pygame.init()
after importing and before creating your screen
Quote
#3
Doing that makes it say that module has no attribute init()
Quote
#4
did you name your file pygame.py?
Quote
#5
No, I named it pygametesteroo.py
Quote
#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.
Quote
#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?
Quote
#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.
Quote
#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
Quote
#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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Battleships Program must display how many ships are left after each turn FnaticPutin 1 229 Oct-24-2017, 03:21 PM
Last Post: Windspar

Forum Jump:


Users browsing this thread: 1 Guest(s)