How to get an windows executable from my kivy app (Pyinstaller)?

夙愿已清 提交于 2020-01-24 10:14:36

问题


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

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.


回答1:


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')

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.




回答2:


The Kivy documentation for this is here.

You probably do have to run this in Windows if you want to create a package for that platform.



来源:https://stackoverflow.com/questions/37696206/how-to-get-an-windows-executable-from-my-kivy-app-pyinstaller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!