简体   繁体   English

无法使用 Pyinstaller 构建 .exe

[英]Can't build .exe using Pyinstaller

I have 2 files, One is Main.py other one is Autoe.ui, I want both as a single .exe I tried我有 2 个文件,一个是 Main.py,另一个是 Autoe.ui,我想将两者都作为一个 .exe 试过

pyinstaller -w --add-data="Autoe.ui;." Main.py

This works just fine, but it creates lot of other files as well, I wanted just a single exe, So I tried this这工作得很好,但它也创建了很多其他文件,我只想要一个 exe,所以我尝试了这个

pyinstaller.exe -w --onefile --add-data="Autoe.ui;." Main.py

This creates a single .exe but it won't run, I get a pop-up saying "Failed to execute script Main"这会创建一个 .exe 但它不会运行,我收到一个弹出窗口,提示“无法执行脚本 Main”

I had a similar problem with the Kivy app.我在 Kivy 应用程序上遇到了类似的问题。 In my case it was a kv file, not a ui.就我而言,它是一个 kv 文件,而不是 ui。 Maybe what I did will help you.也许我所做的会对你有所帮助。 In the folder with the * .py file I ran the command:在带有 * .py 文件的文件夹中,我运行了以下命令:

pyinstaller --onefile -y --clean --windowed --icon=someicon.ico main.py

The main.spec file appeared in the folder. main.spec 文件出现在文件夹中。 I have edited it.我已经编辑了它。

# -*- mode: python ; coding: utf-8 -*-
block_cipher = None

a = Analysis(["main.py"],
             pathex=["C:\\Users\\underground\\Desktop\\gdc"], #<<<<<<<path to folder of your app
             binaries=[]
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
             
a.datas += [('gdc.kv', 'C:\\Users\\underground\\Desktop\\gdc\\gdc.kv', 'DATA')]  #<<<< I added kv file to a.datas
excluded_binaries = ['VCRUNTIME140.dll']                        #<<<< I disabled this library because my app won't start on win10
a.binaries = TOC([x for x in a.binaries if x[0] not in excluded_binaries])

exe = EXE(pyz, Tree('C:\\Users\\underground\\Desktop\\gdc\\Data','Data'), 
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='main',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=False,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=False , icon='ikona.ico')

When I edited the spec file, I ran pyintaller again but gave the spec file instead of the * .py file.当我编辑规范文件时,我再次运行 pyintaller 但给出了规范文件而不是 * .py 文件。

pyinstaller main.spec

...that's all. ...就这样。 You can also try the GUI version - auto-py-to-exe instead of pyinstaller.您也可以尝试使用 GUI 版本 - auto-py-to-exe 而不是 pyinstaller。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM