【问题标题】:Can't seem to deploy pygame app with pyinstaller似乎无法使用 pyinstaller 部署 pygame 应用程序
【发布时间】:2020-04-28 12:42:05
【问题描述】:

尝试使用pyinstaller 捆绑应用程序:

pyinstaller —onefile —debug all —icon=<icon_file> —name=name my_enter_point.py 

但出现以下错误:

import 'pygame
settings not found in PYZ
code object from 
import 'settings' 
shooter not found in PYZ
code object from 
import 'shooter' 
game_functions not found in PYZ
code object from
bullet not found in PYZ

(我尝试使用--paths=.,但我得到了pygame._freetype not found in PYZ

settings shooter bullet 是我自己的模块文件,与 my_enter_point.py 位于同一目录中

所以我的项目看起来像(同一级别的所有文件和图像文件夹):

images_folder

Main file:
import sys
import os
import pygame
from pygame.sprite import Group
from a import A
from b import B
import c as C
from d import D
from e import E
from f import F

file b:
import pygame
from pygame.sprite import Sprite

file g:
import pygame
from pygame.sprite import Sprite

file h:
import pygame
from pygame.sprite import Sprite

file c:
import sys
import pygame
from g import G
from h import H
from time import sleep

file e:
import pygame.ftfont
from pygame.sprite import Group
from b import B

file f:
import pygame.font

【问题讨论】:

    标签: python pygame pyinstaller


    【解决方案1】:

    将您的文件 my_enter_point.py 重命名为 main.py,然后重试。

    编辑: 另外,首先尝试仅使用这些参数pyinstaller --onefile -w main.py

    【讨论】:

    • 没有帮助得到同样的错误(“..在 PYZ 中找不到”)
    • 很抱歉听到这个消息。你的 python/pygame 版本是什么?您是否尝试过简单的示例来查看在这种情况下是否一切正常?
    • python 3.7.4 pygame 1.9.6 是的,简单的例子有效。你能说出“在 PYZ 中找不到”是什么意思吗?
    • .pyz 是一个扩展,其中包含可以由解释器执行的 Python 代码文件。我认为PYZ 是制作某种用于导入的规范文件的类。我不是 100% 确定,所以如果我犯了任何错误,请纠正我,并在需要时提供更多信息。您是否有二级导入(例如 main.py 导入 A 模块,然后在 A 中导入 B)?如果是这样,请更正这一点。还将所有必需的文件放在同一目录中。让我们知道其中任何一项有效
    • 谢谢。我在主线程中添加了项目依赖项。只有 images 文件夹不在同一级别,但我会将该文件夹与 exe 文件放在一起。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-18
    • 1970-01-01
    • 2018-10-08
    • 1970-01-01
    相关资源
    最近更新 更多