我用 TCP、UDP 和 pygame 制作了多人 Pong 游戏。 我使用的模块是:pygame、os、logging、threading、random、yaml (PyYAML) 和 socket
当使用 python2.7 从命令行运行游戏时它运行良好,但是使用 py2app 的编译版本给我一个错误,它是:
TypeError: Error when calling the metaclass bases
function() argument 1 must be code, not str
我用谷歌搜索了一下,关于堆栈溢出的其他问题似乎对我来说没有任何意义。它给我错误的那一行是:
class Entity(pygame.Surface):
def __init__(self, x, y, w, h, color=(255, 255, 255)):
pygame.Surface.__init__(self, (w, h))
您可能已经理解,它位于本示例的第一行。使用 pygame.Surface 时有些奇怪。尽管正如我所说,当我在命令行中运行该程序时它会起作用!
我使用的 py2app 脚本是这样的:
from setuptools import setup
APP = ['src/client.py']
OPTIONS = {'argv_emulation': True, 'includes': ['EXTERNAL LIBRARY'], }
setup(
app=APP,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
提前致谢!
最佳答案
我自己找到了解决方案。在命令行的前面它说:
RuntimeWarning: import transform: No module named _view (ImportError: No module named _view)
显然,这使得“pygame.Surface”无法导入,也无法被计算机识别为函数。所以,错误消息毕竟是有道理的。
关于python - 游戏从源代码运行良好,但不是从 py2app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16230099/