gpt4 book ai didi

python - 导出单个 .exe 时,PyInstaller 卡在 "Building PKG ..."上

转载 作者:行者123 更新时间:2023-12-03 18:32:35 27 4
gpt4 key购买 nike

我写了一个 kivy 程序,我想通过 pyinstaller 将它导出到单个 .exe 文件中。我设法导出到多个文件(标准选项),但是当我将 --onefile 选项添加到 pyinstaller 时,进程卡在一行上说:

    INFO: Building PKG (CArchive) out00-PKG.pkg

有谁知道怎么解决?只是时间问题还是我在导出过程中遗漏了什么?

我的项目:

我正在使用 python 3.6.4、kivy 1.9.0 和 pyinstaller 3.3.1。 main.py 和 main.kv 文件(我只使用了 2 个文件)都在同一个文件夹中,从现在开始我将其称为\project_folder\。在同一个文件夹中还有一个名为 icon.ico 的图标。

我还使用UPX(upx394a),该文件已下载到名为\upx_path\upx394a的文件夹中。

首先,我修改了我的 main.py 文件:
import kivy
import sys
import os

...

def resourcePath():
if hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS)
return os.path.join(os.path.abspath("."))

...

if __name__=='__main__':
kivy.resources.resource_add_path(resourcePath())
MainApp().run()

对于导出,我运行了一个 Windows 提示;我移动到\project_folder\然后导出:
    pyinstaller main.py --onefile --clean -y --windowed --icon=icon.ico 
--name MyApp --upx-dir=\upx_path\upx394a --exclude-module _tkinter
--exclude-module Tkinter --exclude-module enchant --exclude-module twisted

我在以下位置找到了此选项:
Kivy: compiling to a single executable

以这种方式成功创建 .spec 文件后,我继续修改 .spec 文件以正确创建 .exe:

1.
from kivy.deps import sdl2, glew
  • 在“EXE(pyz”之后,我补充说:

    Tree('\...\percorso dove si trova il file main.py\'),
  • 在“a.datas”之后,在下一行我添加:

    *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],

  • 然后我保存.spec文件并从提示符运行:
    python -m PyInstaller MyApp.spec

    在这里,在提示上的一些输出之后,是 pyinstaller 卡住的地方。我试图等待一段时间,但没有任何 react 。

    ** 我的代码:**

    我在这里粘贴我正在使用的代码,希望它有帮助:
    1.主.py
    # python 3.6.4

    from kivy.config import Config
    Config.set('input', 'mouse', 'mouse, multitouch_on_demand')
    # set non resizable window, specify heigth and width
    Config.set('graphics', 'resizable', False)
    Config.set('graphics', 'width', '800')
    Config.set('graphics', 'height', '600')
    Config.set('graphics', 'borderless', False)

    import kivy
    import sys
    import os
    from kivy.app import App
    from kivy.uix.floatlayout import FloatLayout

    # la funzione definita di seguito serve per esportazione in .exe
    def resourcePath():
    if hasattr(sys, '_MEIPASS'):
    return os.path.join(sys._MEIPASS)
    return os.path.join(os.path.abspath("."))

    class RootWidget(FloatLayout):
    pass

    class MainApp(App):
    def build(self):
    return RootWidget()

    if __name__=="__main__":
    kivy.resources.resource_add_path(resourcePath()) # add this line
    MainApp().run()
  • main.kv
    # File name: main.kv
    #:kivy 1.9.0

    #:set logo_image 'logo_1.png'
    <CreditLabel@Label>: # custom class for credits window labels
    size_hint: [.4, .1]
    color: 1, 1, 1, 1

    <RootWidget>:
    TabbedPanel:
    do_default_tab: False
    tab_width: self.parent.width/5
    background_color: 0, 0, 0, 1

    TabbedPanelItem:
    text: 'Benvenuto!'
    color: 1, 0.5, 0, 1
    FloatLayout:
    Label:
    size_hint: .4, .25
    pos_hint: {'center_x': 0.5, 'center_y': 0.7}
    text: 'Benvenuto in MyBaku!'
    font_size: 40
    color: 1, 0.5, 0, 1

    Label:
    size_hint: .6, .25
    pos_hint: {'center_x': 0.5, 'center_y': 0.55}
    text: 'Bentornato Gianpietro! Prenditi il tuo tempo per visualizzare le tue statistiche.'
    font_size: 18
    color: 1, 1, 1, 1
    Label:
    canvas:
    Rectangle:
    size: 80, 80
    pos: self.right - (self.width * 0.15), self.top * 0.8
    source: logo_image

    TabbedPanelItem:
    text: 'Questa notte...'
    color: 1, 0.5, 0, 1
    FloatLayout:

    TabbedPanelItem:
    text: 'Statistiche globali'
    color: 1, 0.5, 0, 1
    FloatLayout:

    TabbedPanelItem:
    text: 'Credits'
    color: 1, 0.5, 0, 1
    FloatLayout:
    Label:
    canvas:
    Rectangle:
    #:set coefficient .3
    size: self.width * coefficient, self.width * coefficient
    pos: self.center_x - (self.width * coefficient)/2, self.top * 0.5
    source: logo_image
    CreditLabel:
    text: 'Software developed by Giampo (dev 0.1)'
    pos_hint: {'center_x': .5, 'center_y': .45}
    CreditLabel:
    text: 'Written with Python 3.6.4 using kivy 1.9.0'
    pos_hint: {'center_x': .5, 'center_y': .40}
    CreditLabel:
    text: 'Trento (Italy) - march 2018'
    pos_hint: {'center_x': .5, 'center_y': .35}
  • 附上卡住提示的截图
    prompt problem screenshot
  • 最佳答案

    尝试删除现有的 build 和 dist 目录,看看它是否解决了问题,这个解决方案对我有用,我在调用 pyinstaller 时也使用了完整路径,因为我有多个版本的 python。

    关于python - 导出单个 .exe 时,PyInstaller 卡在 "Building PKG ..."上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49259036/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com