Kivy py to exe standalone windows application

2,563 views
Skip to first unread message

Ajay Kumar

unread,
Jun 12, 2016, 12:25:49 AM6/12/16
to Kivy users support
Hi Guys, 

I'm Trying to convert the kivy .py file to .exe using pyinstaller, I'm using windows 10 64 bit operating system. First I followed the instruction for installing kivy in windows from this https://kivy.org/docs/installation/installation-windows.html and I did one basic kivy program form the getting started.

import kivy

from kivy.app import App
from kivy.uix.button import Button

class MyApp(App):
    def build(self):
        return Button(text='Hello world')
        
if __name__ == '__main__':
    MyApp().run()

And I run it through console the programs runs well. My Next try is to convert this .py file to standalone windows application .exe , I followed the step from this link https://kivy.org/docs/guide/packaging-windows.html 


step 1
python -m PyInstaller --name hello ..\hello\hello.py
 from this I got some folders structure and a spec file, as mentioned in the document i modified the spec file.

# -*- mode: python -*-

from kivy.deps import sdl2, glew

block_cipher = None


a = Analysis(['..\\hello\\hello.py'],
             pathex=['E:\\projects\\kivy\\app'],
             binaries=None,
             datas=None,
             hiddenimports=[],
             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='hello',
          debug=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,Tree('..\\hello\\'),
               a.binaries,
               a.zipfiles,
               a.datas,
               *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
               strip=False,
               upx=True,
               name='hello')


Step 2:
python -m PyInstaller hello.spec
I executed this command

These are the final logs I got 

115891 INFO: Warnings written to E:\projects\kivy\app\build\hello\warnhello.txt
116418 INFO: checking PYZ
116466 INFO: checking PKG
116466 INFO: Building because E:\projects\kivy\app\build\hello\hello.exe.manifest changed
116466 INFO: Building PKG (CArchive) out00-PKG.pkg
116668 INFO: Bootloader C:\Python27\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
116668 INFO: checking EXE
116668 INFO: Rebuilding out00-EXE.toc because pkg is more recent
116684 INFO: Building EXE from out00-EXE.toc
116684 INFO: Appending archive to EXE E:\projects\kivy\app\build\hello\hello.exe
116793 INFO: checking Tree
116793 INFO: Building Tree because out02-Tree.toc is non existent
116793 INFO: Building Tree out02-Tree.toc
116793 INFO: checking Tree
116793 INFO: Building Tree because out03-Tree.toc is non existent
116809 INFO: Building Tree out03-Tree.toc
116841 INFO: checking Tree
116841 INFO: Building Tree because out04-Tree.toc is non existent
116841 INFO: Building Tree out04-Tree.toc
116871 INFO: checking COLLECT
WARNING: The output directory "E:\projects\kivy\app\dist\hello" and ALL ITS CONTENTS will be REMOVED! Continue? (y/n)y
121427 INFO: Removing dir E:\projects\kivy\app\dist\hello
121677 INFO: Building COLLECT out00-COLLECT.toc
121740 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9177)

E:\projects\kivy\app>

I didn't get what happen here and I cant find my exe file any where, Guy please help me for this, If anything I missed please suggest me and let me know where i need to improve. Thanks in advance.



Usman Ahmad

unread,
Sep 11, 2018, 5:59:01 PM9/11/18
to Kivy users support
Hey - Ajay - i see you have had no response to this. I have got a similar issue where i do the last line you suggest:

python -m PyInstaller hello.spec

And my dist folder is empty, no exe.

Have you had any luck on this since '16? i hope so? :) any help would be much appreciated. 

Thanks,
Usman

Leandro V C Castelani

unread,
Mar 31, 2020, 3:41:36 PM3/31/20
to Kivy users support
I've tried the same thing and got this error:

PS G:\Meu Drive\Bairru\Tecnologia\01 - Projetos\1.1 - Automação de processos\1.1.2 -Carteira\Painel de Clientes\Executavel> python -m PyInstaller Painel.spec
111 INFO: PyInstaller: 3.6
111 INFO: Python: 3.8.2
114 INFO: Platform: Windows-10-10.0.18362-SP0
118 INFO: UPX is not available.
Traceback (most recent call last):
  File "C:\Users\leh32\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\leh32\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\leh32\AppData\Roaming\Python\Python38\site-packages\PyInstaller\__main__.py", line 121, in <module>
    run()
  File "C:\Users\leh32\AppData\Roaming\Python\Python38\site-packages\PyInstaller\__main__.py", line 114, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "C:\Users\leh32\AppData\Roaming\Python\Python38\site-packages\PyInstaller\__main__.py", line 65, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "C:\Users\leh32\AppData\Roaming\Python\Python38\site-packages\PyInstaller\building\build_main.py", line 734, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "C:\Users\leh32\AppData\Roaming\Python\Python38\site-packages\PyInstaller\building\build_main.py", line 681, in build
    exec(code, spec_namespace)
  File "Painel.spec", line 3, in <module>
    from kivy.deps import sdl2, glew
ModuleNotFoundError: No module named 'kivy'

Elliot Garbus

unread,
Mar 31, 2020, 4:41:22 PM3/31/20
to kivy-...@googlegroups.com

The binary wheels are not built for python 3.8, use python 3.7

Assuming you are using kivy 1.11.1

 

You need to import:

from kivy_deps import sdl2, glew

NOT: kivy.deps

 

Below is the spec file I use to build Windows10 programs.  It is worth recognizing that the spec file is python code, you can add print statements to help figure out what is going on.  Change the highlighted areas below to customize for your program.

Here is the best video on Pyinstaller I have found to date: https://youtu.be/tOTLqUQC-k0

 

 

 

# -*- mode: python -*-

import os
from kivy_deps import sdl2, glew

spec_root = os.path.abspath(SPECPATH)
block_cipher =
None
app_name = 'Chase Bliss Editor'
win_icon = '../Images/cb_icon.ico'

a = Analysis(['../main.py'],
            
pathex=[spec_root],
            
datas=[('../*.kv', '.'), ('../Images/*.png', './Images')],
            
hiddenimports=['win32timezone'],
            
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)
exe = EXE(pyz,
          a.scripts,
          [],
         
exclude_binaries=True,
         
name=app_name,
         
debug=False,
         
bootloader_ignore_signals=False,
         
strip=False,
         
upx=False,
         
console=False,
         
icon=win_icon)
coll = COLLECT(exe,

               a.binaries,
               a.zipfiles,
               a.datas,
               *[Tree(p)
for p in (sdl2.dep_bins + glew.dep_bins)],
              
strip=False,
              
upx=False,
              
name=app_name)

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/5cc370a0-7262-4e0d-95b8-0f01a13818bc%40googlegroups.com.

 

Reply all
Reply to author
Forward
0 new messages