Kivy 1.9.1 Windows软件包.spec单个exe [英] Kivy 1.9.1 Windows package .spec single exe

查看:49
本文介绍了Kivy 1.9.1 Windows软件包.spec单个exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的应用制作一个Windows软件包,其中大多数文件都位于.exe中.根据 Kivy-在Windows上创建程序包,我安装了setuptools 19.2.我使用Kivy 1.9.1稳定版.

I want to make a Windows package of my app with most files being in the .exe. According to Kivy - Create package on Windows I installed setuptools 19.2. I'm on Kivy 1.9.1 stable.

根据 https://kivy.org/docs/guide/上的说明packaging-windows.html 我得到了以下有效 .spec文件:

According to the instructions on https://kivy.org/docs/guide/packaging-windows.html I got the following working .spec file:

from kivy.deps import sdl2, glew
# -*- mode: python -*-

block_cipher = None


a = Analysis(['..\\foo\\main.py'],
             pathex=['path\\KO-exe'],
             binaries=None,
             datas=None,
             hiddenimports=['six','packaging','packaging.version','webbrowser'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          exclude_binaries=True,
          name='foo',
          debug=False,
          strip=False,
          upx=True,
          console=True , icon='..\\foo\\ko.ico')
coll = COLLECT(exe, Tree('..\\foo\\'),
               a.binaries,
               a.zipfiles,
               a.datas,
               *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins )],
               strip=False,
               upx=True,
               name='foo')

但是,我最终得到一个包含许多文件的文件夹,而不是我可以分发给其他人的文件夹.因此,通过添加命令--onefile并将相同的步骤应用于.spec文件,我得到以下 NOT WORKING .spec:

However I end up with a folder with many files, not something I can distribute to other people. So with adding the command --onefile and applying the same steps to the .spec file, I get the following NOT WORKING .spec:

# -*- mode: python -*-
from kivy.deps import sdl2, glew

block_cipher = None


a = Analysis(['..\\foo\\main.py'],
             pathex=['path\\KO-exe'],
             binaries=None,
             datas=None,
             hiddenimports=['six','packaging','packaging.version','webbrowser'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz, Tree('..\\foo\\'),
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins )],
          name='foo',
          debug=False,
          strip=False,
          upx=True,
          console=True , icon='..\\foo\\ko.ico')

错误: .exe仅在build文件夹中而不在dist中,并且在运行时:Error loading Python DLL: C:\Users\user\AppData\Local\Temp\_MEI81162\python27.dll (error code 126)

Error: .exe only in build folder and not in dist, and when running: Error loading Python DLL: C:\Users\user\AppData\Local\Temp\_MEI81162\python27.dll (error code 126)

我一直在尝试将工作.spec和单个.spec进行各种组合(添加COLLECT,移动Tree('..\\foo\\')),但无济于事.

I've been trying to make all kinds of combinations of the working .spec and the single .spec (adding COLLECT, moving Tree('..\\foo\\') around), but to no avail.

  • 要运行单个.exe,我应该怎么做?
  • 如何选择要排除的文件/文件夹? (我应该在Tree()中使用哪种语法?)
  • 除了data \ db \ database.db(在.exe中太慢)之外,我几乎希望在.exe中包含所有内容.我该怎么办?
  • What should I change to have a working single .exe?
  • How can I select files/folder to exclude? (what syntax should I use in Tree()?)
  • I want almost everything inside the .exe, besides data\db\database.db (too slow in a .exe). How do I do this?

在@tito的帮助下工作的.spec文件:

The working .spec file with help From @tito:

from kivy.deps import sdl2, glew
# -*- mode: python -*-
#import pdb
import sys

sys.path += ["..\\foo\\"]

block_cipher = pyi_crypto.PyiBlockCipher(key='1234567890')

#'six','packaging','packaging.version',
a = Analysis(['..\\foo\\main.py'],
             pathex=['D:\\path\\KO-exe'],
             binaries=None,
             datas=None,

             hiddenimports=[
             'webbrowser',
             '__init__',
             'data.__init__',
             'data.screens.__init__',
             'data.screens.dbmanager',
             'data.screens.db_kv.__init__',
             'data.screens.db_kv.backupsd',
             ],

             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)

#pdb.set_trace()

# exclusion list
from os.path import join
from fnmatch import fnmatch
exclusion_patterns = (
    join("kivy_install", "data", "images", "testpattern.png"),
    join("kivy_install", "data", "images", "image-loading.gif"),
    join("kivy_install", "data", "keyboards*"),
    join("kivy_install", "data", "settings_kivy.json"),
    join("kivy_install", "data", "logo*"),
    join("kivy_install", "data", "fonts", "DejaVuSans*"),
    join("kivy_install", "modules*"),
    join("Include*"),
    join("sdl2-config"),
    # Filter app directory
    join("personal*"),
    join("sign-apk*"),
    join(".idea*"),
)

def can_exclude(fn):
    for pat in exclusion_patterns:
        if fnmatch(fn, pat):
            return True

a.datas = [x for x in a.datas if not can_exclude(x[0])]
a.binaries = [x for x in a.binaries if not can_exclude(x[0])]
# Filter app directory
appfolder = [x for x in Tree('..\\foo\\', excludes=['*.py','*.pyc']) if not can_exclude(x[0])]  

#print(a.zipped_data)

#pdb.set_trace()

pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)

exe = EXE(pyz,
          a.scripts,
          exclude_binaries=True,
          name='foo',
          debug=True,
          strip=False,
          upx=True,
          console=True , icon='..\\foo\\ko.ico')
coll = COLLECT(exe, appfolder,
               a.binaries,
               a.zipfiles,
               a.datas,
               *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins )],
               strip=False,
               upx=True,
               name='foo')

我想从我的应用程序文件夹中排除文件夹和文件,感谢tito,通过我,我也弄清楚了如何过滤Tree().

I wanted to exclude folders and files from my app folder, and thanks tito, through you I figured out how to filter Tree() as well.

让PyInstaller排除文件后,我将尝试在输出文件上运行NSIS.

After getting PyInstaller to exclude files, I'll try running NSIS over the output files.

推荐答案

Imo,我不知道为什么您的应用程序因文件模式而失败.但是由于暗示从pyinstaller使用onefile模式(它将在临时目录中每次运行时解压缩文件),因此最好使用

Imo, i don't know exactly why your application is failing with onefile mode. But because of the implication of using onefile mode from pyinstaller (it will decompress the files every run in a temporary directory), it might be better to do an installer with NSIS.

要选择要排除的模块,可以将它们放在Analysisexcludes参数中:

To select modules to excludes, you can put them in the excludes parameters in your Analysis:

excludes=["pickle", "csv"]

要排除文件,我通常在分析之后/在EXE之前进行手动排除.这是一个示例:

To excludes files, i'm usually doing a manual exclusion after analysis / before EXE. Here is an example:

# exclusion list
from fnmatch import fnmatch
exclusion_patterns = (
    join("kivy_install", "data", "images", "testpattern.png"),
    join("kivy_install", "data", "images", "image-loading.gif"),
    join("kivy_install", "data", "keyboards*"),
    join("kivy_install", "data", "settings_kivy.json"),
    join("kivy_install", "data", "logo*"),
    join("kivy_install", "data", "fonts", "DejaVuSans*"),
    join("kivy_install", "modules*"),
    join("Include*"),
    join("sdl2-config"),
)

def can_exclude(fn):
    for pat in exclusion_patterns:
        if fnmatch(fn, pat):
            return True
a.datas = [x for x in a.datas if not can_exclude(x[0])]
a.binaries = [x for x in a.binaries if not can_exclude(x[0])]

这篇关于Kivy 1.9.1 Windows软件包.spec单个exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆