Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyInstaller stuck on "Building PKG ..." when exporting a single .exe

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
  1. after "EXE(pyz," I add:

    Tree('\...\percorso dove si trova il file main.py\'),

  2. 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()
  1. 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}
    
  2. attach a screenshot of the stuck prompt prompt problem screenshot

like image 382
DJappo Avatar asked Mar 13 '18 14:03

DJappo


People also ask

Why is my PyInstaller exe not working?

The most common reason a PyInstaller package fails is that PyInstaller failed to bundle a required file. Such missing files fall into a few categories: Hidden or missing imports: Sometimes PyInstaller can't detect the import of a package or library, typically because it is imported dynamically.

Does PyInstaller need UPX?

PyInstaller looks for UPX on the execution path or the path specified with the --upx-dir option. If UPX exists, PyInstaller applies it to the final executable, unless the --noupx option was given. UPX has been used with PyInstaller output often, usually with no problems.

Where does PyInstaller save EXE?

PyInstaller generates the executable that is a bundle of your game. It puts it in the dist\ folder under your current working directory.

What is Onefile in PyInstaller?

When we specify the onefile option, to the PyInstaller, it unpacks all the files to a TEMP directory, executes the file, and later discard the TEMP folder. When you specify the add-data option along with onefile, then you need to read the data referred to in the TEMP folder.


2 Answers

Try deleting the existing build and dist directory, and see if it solves the problem, this solution worked for me, i also used the full path when calling the pyinstaller, cause i have multiple version of python.

like image 109
Stefano Raneri Avatar answered Oct 13 '22 04:10

Stefano Raneri


I had the same problem, with the same "INFO:". I forgot to run cmd as administrator... After I ran this way, it was able to complete the conversion.

like image 38
dbobo4 Avatar answered Oct 13 '22 06:10

dbobo4