Wireframe-Magazine / Wireframe-21

Projects and assets from Wireframe #21
Other
5 stars 3 forks source link

pygame.error: cannot convert without pygame.display initialized #3

Open nils-werner opened 5 years ago

nils-werner commented 5 years ago

After adding the line

from pgzero.actor import Actor

to work around issue #2 I get the following traceback

(speed) [me@mac Wireframe-21 (master)]$ python supersprint.py 
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
Traceback (most recent call last):
  File "supersprint.py", line 10, in <module>
    cars.append(Actor('car'+str(c), center=(400, 70+(30*c))))
  File "/Users/me/Projekte/speed/lib/python3.7/site-packages/pgzero/actor.py", line 88, in __init__
    self.image = image
  File "/Users/me/Projekte/speed/lib/python3.7/site-packages/pgzero/actor.py", line 103, in __setattr__
    return object.__setattr__(self, attr, value)
  File "/Users/me/Projekte/speed/lib/python3.7/site-packages/pgzero/actor.py", line 218, in image
    self._orig_surf = self._surf = loaders.images.load(image)
  File "/Users/me/Projekte/speed/lib/python3.7/site-packages/pgzero/loaders.py", line 138, in load
    res = self.cache[key] = self._load(p, *args, **kwargs)
  File "/Users/me/Projekte/speed/lib/python3.7/site-packages/pgzero/loaders.py", line 160, in _load
    return pygame.image.load(path).convert_alpha()
pygame.error: cannot convert without pygame.display initialized

After installing pgzero I have the following libraries installed:

Package    Version
---------- -------
numpy      1.17.1 
pgzero     1.2    
pip        19.2.3 
pygame     1.9.6  
setuptools 41.2.0 
wheel      0.33.6 
S3riousSam commented 1 year ago

I got the same issue... and could only work around it launching the script with pgzrun: pgzrun supersprint.py

Alternatively I could make it run with: python3 supersprint.py

...Only after performing these changes in the script:

Adding (before the first image.load(...) call):

pygame.init()
pygame.display.init()
pygame.display.set_mode((1024, 768))

...and ending the script with:

import pgzrun
pgzrun.go()