【问题标题】:Game runs well from source, but not from py2app游戏从源代码运行良好,但不是从 py2app
【发布时间】:2013-04-26 06:32:33
【问题描述】:

我用 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:导入转换:没有名为 _view 的模块(ImportError:没有名为 _view 的模块)显然,这使得 pygame.Surface 无法导入并且未被计算机识别为函数。因此,错误消息毕竟是有道理的
  • 不能,显然我需要 10 个声望才能在 8 小时内自己回答
  • @Zenolijo 哦,你现在有 10 多个 :)。

标签: python python-2.7 py2app


【解决方案1】:

自己找到了解决方案。在命令行的前面它说:

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

显然,这使得 'pygame.Surface` 无法导入,也无法被计算机识别为函数。所以,错误信息毕竟是有道理的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-07
    • 2012-04-06
    • 2017-06-16
    • 1970-01-01
    相关资源
    最近更新 更多