2

我正在尝试使用 nuitka 编译一个非常简单的 pygame 脚本。这是脚本(main.py)

import pygame

pygame.init()
screen = pygame.display.set_mode((640, 480))
clock = pygame.time.Clock()
done = False

font = pygame.font.SysFont("comicsansms", 72)

text = font.render("Hello World", True, (0, 128, 0))

while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
        if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
            done = True

    screen.fill((255, 255, 255))
    screen.blit(text,
        (320 - text.get_width() // 2, 240 - text.get_height() // 2))

    pygame.display.flip()
    clock.tick(60)

首先我尝试编译它: python3 -m nuitka --standalone main.py 导致所有这些警告(但完成):

Nuitka:WARNING:Use '--plugin-enable=numpy' for: numpy support.
Nuitka:WARNING:Unresolved '__import__' call at '/usr/lib/python3/dist-packages/OpenGL/plugins.py:38' may require use of '--include-plugin-directory' or '--include-plugin-files'.
Nuitka:WARNING:Unresolved '__import__' call at '/usr/lib/python3/dist-packages/numpy/core/function_base.py:453' may require use of '--include-plugin-directory' or '--include-plugin-files'.
Nuitka:WARNING:Unresolved '__import__' call at '/usr/lib/python3/dist-packages/numpy/lib/utils.py:366' may require use of '--include-plugin-directory' or '--include-plugin-files'.
Nuitka:WARNING:Unresolved '__import__' call at '/usr/lib/python3/dist-packages/numpy/lib/utils.py:865' may require use of '--include-plugin-directory' or '--include-plugin-files'.
Nuitka:WARNING:Unresolved '__import__' call at '/usr/lib/python3/dist-packages/numpy/lib/utils.py:923' may require use of '--include-plugin-directory' or '--include-plugin-files'.

运行生成的二进制文件时,会打开一个黑色窗口,然后崩溃:

Fatal Python error: (pygame parachute) Segmentation Fault
Traceback (most recent call last):
  File "/home/xxxxx/git/sesyn/paradigm10123/main.dist/pygame/pkgdata.py", line 51, in getResource
  File "/home/xxxxx/git/sesyn/paradigm10123/main.dist/pkg_resources/__init__.py", line 1134, in resource_exists
  File "/home/xxxxx/git/sesyn/paradigm10123/main.dist/pkg_resources/__init__.py", line 1404, in has_resource
  File "/home/xxxxx/git/sesyn/paradigm10123/main.dist/pkg_resources/__init__.py", line 1473, in _has
NotImplementedError: Can't perform this operation for unregistered loader type
Aborted (core dumped)

所以我修改了 getResource 函数,它在它崩溃的地方打印出它试图加载的文件。然后我通过--include-plugin-files命令添加了这些文件: python3 -m nuitka --standalone main.py --include-plugin-files=/home/xxxxx/.local/lib/python3.7/site-packages/pygame/pygame_icon.bmp --include-plugin-files=/home/xxxxx/.local/lib/python3.7/site-packages/pygame/freesansbold.ttf但是运行生成的二进制文件会产生完全相同的崩溃。

我还尝试将 OpenGL 目录添加为 plugin-dir 并使用了 numpy 插件(我不知道这里有任何 numpy 用法,但是嘿,我认为它不会受到伤害)

python3 -m nuitka --standalone main.py --include-plugin-files=/home/xxxxx/.local/lib/python3.7/site-packages/pygame/pygame_icon.bmp --include-plugin-files=/home/xxxxx/.local/lib/python3.7/site-packages/pygame/freesansbold.ttf --include-plugin-directory=/usr/lib/python3/dist-packages/OpenGL/ --enable-plugin=numpy(现在编译大约需要 30 分钟)但生成的二进制文件仍然会产生完全相同的崩溃。有谁知道如何使这个运行?

哦,顺便说一句,我在 Ubuntu 19.10 上使用系统 python

$ python3 -c "import pygame"
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
$ python3 -m nuitka --version
0.6.7
Python: 3.7.5 (default, Nov 20 2019, 09:21:52) 
Executable: /usr/bin/python3
OS: Linux
Arch: x86_64
$ gcc --version
gcc (Ubuntu 9.2.1-9ubuntu2) 9.2.1 20191008
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
4

0 回答 0