I wrote a kivy program which I want to export into a single .exe file through pyinstaller. I managed to export to multiple files (standard option) but when I add the --onefile option to pyinstaller the process get stuck on a line saying:
INFO: Building PKG (CArchive) out00-PKG.pkg
Does anyone know how to solve? Is just a matter of time or am I missing something in the exportation process?
MY PROJECT:
I am using python 3.6.4, kivy 1.9.0 and pyinstaller 3.3.1. Both the main.py and the main.kv files (only 2 files I am using) are in the same folder, which I will refer to as \project_folder\ from now on. In the same folder there is also an icon called icon.ico.
I am also using UPX (upx394a) which is downloaded in a folder called \upx_path\upx394a.
First of all, I modified my main.py file with:
import kivy
import sys
import os
...
def resourcePath():
if hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS)
return os.path.join(os.path.abspath("."))
...
if __name__=='__main__':
kivy.resources.resource_add_path(resourcePath())
MainApp().run()
For the exportation I run a windows prompt; i move to the \project_folder\ and then export with:
pyinstaller main.py --onefile --clean -y --windowed --icon=icon.ico
--name MyApp --upx-dir=\upx_path\upx394a --exclude-module _tkinter
--exclude-module Tkinter --exclude-module enchant --exclude-module twisted
I found this options on: Kivy: compiling to a single executable
After succesfully creating the .spec file this way, I proceed to modify the .spec file to properly create the .exe:
1.
from kivy.deps import sdl2, glew
after "EXE(pyz," I add:
Tree('\...\percorso dove si trova il file main.py\'),
after "a.datas," on the next line I add:
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
then I save the .spec file and run from the prompt:
python -m PyInstaller MyApp.spec
and here, after some output on the prompt, is where pyinstaller get stuck. I tried waiting some time but nothing happens.
** MY CODE: **
Here I paste the code I am working with, hope it helps: 1. main.py
# python 3.6.4
from kivy.config import Config
Config.set('input', 'mouse', 'mouse, multitouch_on_demand')
# set non resizable window, specify heigth and width
Config.set('graphics', 'resizable', False)
Config.set('graphics', 'width', '800')
Config.set('graphics', 'height', '600')
Config.set('graphics', 'borderless', False)
import kivy
import sys
import os
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
# la funzione definita di seguito serve per esportazione in .exe
def resourcePath():
if hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS)
return os.path.join(os.path.abspath("."))
class RootWidget(FloatLayout):
pass
class MainApp(App):
def build(self):
return RootWidget()
if __name__=="__main__":
kivy.resources.resource_add_path(resourcePath()) # add this line
MainApp().run()
main.kv
# File name: main.kv #:kivy 1.9.0 #:set logo_image 'logo_1.png' <CreditLabel@Label>: # custom class for credits window labels size_hint: [.4, .1] color: 1, 1, 1, 1 <RootWidget>: TabbedPanel: do_default_tab: False tab_width: self.parent.width/5 background_color: 0, 0, 0, 1 TabbedPanelItem: text: 'Benvenuto!' color: 1, 0.5, 0, 1 FloatLayout: Label: size_hint: .4, .25 pos_hint: {'center_x': 0.5, 'center_y': 0.7} text: 'Benvenuto in MyBaku!' font_size: 40 color: 1, 0.5, 0, 1 Label: size_hint: .6, .25 pos_hint: {'center_x': 0.5, 'center_y': 0.55} text: 'Bentornato Gianpietro! Prenditi il tuo tempo per visualizzare le tue statistiche.' font_size: 18 color: 1, 1, 1, 1 Label: canvas: Rectangle: size: 80, 80 pos: self.right - (self.width * 0.15), self.top * 0.8 source: logo_image TabbedPanelItem: text: 'Questa notte...' color: 1, 0.5, 0, 1 FloatLayout: TabbedPanelItem: text: 'Statistiche globali' color: 1, 0.5, 0, 1 FloatLayout: TabbedPanelItem: text: 'Credits' color: 1, 0.5, 0, 1 FloatLayout: Label: canvas: Rectangle: #:set coefficient .3 size: self.width * coefficient, self.width * coefficient pos: self.center_x - (self.width * coefficient)/2, self.top * 0.5 source: logo_image CreditLabel: text: 'Software developed by Giampo (dev 0.1)' pos_hint: {'center_x': .5, 'center_y': .45} CreditLabel: text: 'Written with Python 3.6.4 using kivy 1.9.0' pos_hint: {'center_x': .5, 'center_y': .40} CreditLabel: text: 'Trento (Italy) - march 2018' pos_hint: {'center_x': .5, 'center_y': .35}
attach a screenshot of the stuck prompt prompt problem screenshot