Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Game runs well from source, but not from py2app

I have made a multiplayer Pong game with TCP, UDP and pygame. the modules i'm using are: pygame, os, logging, threading, random, yaml (PyYAML) and socket

When running the game from the commandline with python2.7 it works well, but the compiled version with py2app gives me a error which is:

TypeError: Error when calling the metaclass bases
    function() argument 1 must be code, not str

I have googled around, and the other questions about this on stack overflow doesn't make any sense in my case it seems. The line where it gives me the error is:

class Entity(pygame.Surface):
    def __init__(self, x, y, w, h, color=(255, 255, 255)):
        pygame.Surface.__init__(self, (w, h))

As you might have understood, it's on the first line of this example. It's something wierd when using pygame.Surface. Though as i said, it works when i run the program in the commandline!

The py2app script i use goes like this:

from setuptools import setup

    APP = ['src/client.py']
    OPTIONS = {'argv_emulation': True, 'includes': ['EXTERNAL LIBRARY'], }

    setup(
        app=APP,
        options={'py2app': OPTIONS},
        setup_requires=['py2app'],
    )

Thanks in advance!

like image 436
Johan Bjäreholt Avatar asked Oct 21 '22 11:10

Johan Bjäreholt


1 Answers

Found the solution myself. Earlier in the command line it said:

RuntimeWarning: import transform: No module named _view (ImportError: No module named _view) 

Apparently, that made it so 'pygame.Surface` could not be imported and was not recognized as a function by the computer. So, the error message made sense after all.

like image 160
Johan Bjäreholt Avatar answered Oct 27 '22 09:10

Johan Bjäreholt