如何从我的Kivy应用程序(Pyinstaller)中获取Windows可执行文件? [英] How to get an windows executable from my kivy app (Pyinstaller)?

查看:296
本文介绍了如何从我的Kivy应用程序(Pyinstaller)中获取Windows可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完成了一个kivy应用程序,并使用buildozer将其打包为.apk.事实是,现在我想使用Pyinstaller打包Windows的.exe,但我意识到这两个程序(buildozer和Pyinstaller)不能以相同的方式工作.我一直在寻找可以帮助我获取文件的优秀教程,但是我看到的所有教程都太简单了,例如,不解释如何导入main.py的外部文件(例如图像)和如何导入外部模块(在buildozer中,我必须将想要的库添加到apk文件中才能正常工作).我在Ubuntu中工作(如果要获取Windows可执行文件,我应该在Windows中工作吗?),并且我有添加到.apk中的列表才能正常工作.列表是:

I've done a kivy app and I packaged to an .apk with buildozer. The fact is that now I want to package in a .exe for windows with Pyinstaller but I have realised that this two programs (buildozer and Pyinstaller), don't work in the same way. I've been looking for a good tutorial that could help me to get the file, but all the tutorials I have seen are too simple and don't explain for example how to import external files of the main.py (e.g. images) and how to import external modules (In buildozer I had to add the libraries I wanted to the apk file to work properly). I'm working in Ubuntu ( Should I work in windows if I want to get an executable for windows?) and I have the list I added to my .apk to work properly. The list is:

requirements = kivy,sqlite3,requests,simplejson,icalendar,datetime,pytz,HTMLParser,email,openssl

如果有人可以告诉我如何添加其他文件(main.py是主文件,但是我有2个其他文件又导入了main.py),我会很高兴,因为我尝试了很多次直到不起作用.

If somebody could tell me how to add the another files (main.py is the master file but I have 2 other files that are imported in main.py) I would be very pleased, because I have tried a lot of times and untill doesn't work.

推荐答案

您必须在Windows环境中运行PyInstaller yourfile.spec. 我可以共享一个我正在使用的规格文件作为示例.

You have to run PyInstaller yourfile.spec on a windows environment. I can share a spec file I am using just as an example.

# -*- mode: python -*-

import os
from os.path import join

from kivy import kivy_data_dir
from kivy.deps import sdl2, glew
from kivy.tools.packaging import pyinstaller_hooks as hooks

block_cipher = None
kivy_deps_all = hooks.get_deps_all()
kivy_factory_modules = hooks.get_factory_modules()

datas = [
    (join('common', '*.ini'), 'common')
]

# list of modules to exclude from analysis
excludes_a = ['Tkinter', '_tkinter', 'twisted', 'docutils', 'pygments']

# list of hiddenimports
hiddenimports = kivy_deps_all['hiddenimports'] + kivy_factory_modules

# binary data
sdl2_bin_tocs = [Tree(p) for p in sdl2.dep_bins]
glew_bin_tocs = [Tree(p) for p in glew.dep_bins]
bin_tocs = sdl2_bin_tocs + glew_bin_tocs

# assets
kivy_assets_toc = Tree(kivy_data_dir, prefix=join('kivy_install', 'data'))
source_assets_toc = Tree('images', prefix='images')
assets_toc = [kivy_assets_toc, source_assets_toc]

tocs = bin_tocs + assets_toc

a = Analysis(['yourmain.py'],
             pathex=[os.getcwd()],
             binaries=None,
             datas=datas,
             hiddenimports=hiddenimports,
             hookspath=[],
             runtime_hooks=[],
             excludes=excludes_a,
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)


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


exe1 = EXE(pyz,
          a.scripts,
          name='mywindowsapplication',
          exclude_binaries=True,
          icon=join('images', 'mywinapp.ico'),
          debug=False,
          strip=False,
          upx=True,
          console=False)


coll = COLLECT(exe1,
               a.binaries,
               a.zipfiles,
               a.datas,
               *tocs,
               strip=False,
               upx=True,
               name='mywinapp')

将"myfile.spec"文件放在"yourmain.py"文件所在的目录中.然后从该目录运行PyInstaller myfile.spec.将创建一个构建和一个dist文件夹.在dist文件夹中,您可能会找到您的exe. 希望这可以帮助您.

Put the 'myfile.spec' file in the same directory where your 'yourmain.py' file is present. Then run PyInstaller myfile.spec from this directory. A build and a dist folder will be created. In the dist folder you may find your exe. Hope this gets you going.

这篇关于如何从我的Kivy应用程序(Pyinstaller)中获取Windows可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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