Reputation: 50
I've built a .exe on Windows 10 using PyInstaller. When I run the executable, a window opens but it doesn't display any widgets, only a blank screen. Output doesn't show any errors, as far as I can make out. Using python 2.7 (Enthought Canopy) with Kivy 1.9.1. When I run the original source file, everything works perfectly; it's only the .exe that fails.
My .spec file looks like this:
# -*- mode: python -*-
from kivy.deps import sdl2, glew, gstreamer
block_cipher = None
a = Analysis(['C:\\Users\\Christiaan\\Documents\\lifeq_dp_pp_p\\toolbox\\ui\\data_importer\\PhoenixKv.py'],
pathex=['C:\\Users\\Christiaan\\Documents\\Phoenix'],
binaries=None,
datas=[('C:\\Users\\Christiaan\\Documents\\lifeq_dp_pp_p\\toolbox\\ui\\data_importer\\dev_ids.json', '.'), ('C:\\Users\\Christiaan\\Documents\\lifeq_dp_pp_p\\toolbox\\ui\\data_importer\\ref_ids.json', '.')],
hiddenimports=['sqlalchemy.ext.hybrid'],
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='phoenix',
debug=True,
strip=False,
upx=False,
console=True )
coll = COLLECT(exe, Tree('C:\\Users\\Christiaan\\Documents\\lifeq_dp_pp_p'),
a.binaries,
a.zipfiles,
a.datas + [('dev_ids.json', 'C:\\Users\\Christiaan\\Documents\\lifeq_dp_pp_p\\toolbox\\ui\\data_importer\\', 'DATA'), ('ref_ids.json', 'C:\\Users\\Christiaan\\Documents\\lifeq_dp_pp_p\\toolbox\\ui\\data_importer\\', 'DATA')],
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
strip=False,
upx=False,
name='phoenix')
and my output when running is:
PyInstaller Bootloader 3.x
LOADER: executable is C:\Users\Christiaan\Documents\Phoenix\dist\phoenix\phoenix.exe
LOADER: homepath is C:\Users\Christiaan\Documents\Phoenix\dist\phoenix
LOADER: _MEIPASS2 is NULL
LOADER: archivename is C:\Users\Christiaan\Documents\Phoenix\dist\phoenix\phoenix.exe
LOADER: No need to extract files to run; setting extractionpath to homepath
LOADER: SetDllDirectory(C:\Users\Christiaan\Documents\Phoenix\dist\phoenix)
LOADER: Already in the child - running user's code.
LOADER: Python library: C:\Users\Christiaan\Documents\Phoenix\dist\phoenix\python27.dll
LOADER: Loaded functions from Python library.
LOADER: Manipulating environment (sys.path, sys.prefix)
LOADER: sys.prefix is C:\Users\CHRIST~1\DOCUME~1\Phoenix\dist\phoenix
LOADER: Setting runtime options
LOADER: Initializing python
LOADER: Overriding Python's sys.path
LOADER: Post-init sys.path is C:\Users\Christiaan\Documents\Phoenix\dist\phoenix
LOADER: Setting sys.argv
LOADER: setting sys._MEIPASS
LOADER: importing modules from CArchive
LOADER: extracted struct
LOADER: callfunction returned...
LOADER: extracted pyimod01_os_path
LOADER: callfunction returned...
LOADER: extracted pyimod02_archive
LOADER: callfunction returned...
LOADER: extracted pyimod03_importers
LOADER: callfunction returned...
LOADER: Installing PYZ archive with Python modules.
LOADER: PYZ archive: out00-PYZ.pyz
LOADER: Running pyiboot01_bootstrap.py
LOADER: Running pyi_rth_win32comgenpy.py
LOADER: Running pyi_rth__tkinter.py
LOADER: Running pyi_rth_pkgres.py
LOADER: Running pyi_rth_kivy.py
LOADER: Running pyi_rth_mplconfig.py
LOADER: Running pyi_rth_mpldata.py
LOADER: Running pyi_rth_gstreamer.py
LOADER: Running pyi_rth_qt4plugins.py
Qt: Untested Windows version 10.0 detected!
LOADER: Running PhoenixKv.py
Purge log fired. Analysing...
Purge 5 log files
Purge finished!
[INFO ] [Logger ] Record log in C:\Users\Christiaan\.kivy\logs\kivy_16-02-08_23.txt
[INFO ] [Kivy ] v1.9.1
[INFO ] [Python ] v2.7.6 |CUSTOM| (default, Sep 15 2014, 17:36:35) [MSC v.1500 64 bit (AMD64)]
[INFO ] [Factory ] 179 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_gif, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO ] [OSC ] using <thread> for socket
[INFO ] [Window ] Provider: sdl2
[INFO ] [GL ] GLEW initialization succeeded
[INFO ] [GL ] OpenGL version <4.5.13397 Compatibility Profile Context 0>
[INFO ] [GL ] OpenGL vendor <ATI Technologies Inc.>
[INFO ] [GL ] OpenGL renderer <AMD Radeon HD 8870M>
[INFO ] [GL ] OpenGL parsed version: 4, 5
[INFO ] [GL ] Shading version <4.40>
[INFO ] [GL ] Texture max size <16384>
[INFO ] [GL ] Texture max units <32>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[INFO ] [Text ] Provider: sdl2
Successfully added file types.
Successfully added file types.
platform: Windows
[INFO ] [Base ] Start application main loop
Upvotes: 2
Views: 4941
Reputation: 11
I was reviewing some documentation and I think you can also do the following:
Builder.load_file("./filename.kv")
That way you don't have to do what I recommended in my other post.
Just remember that is you run it from python, you will have to comment out the Builder.load_file line.
Upvotes: 0
Reputation: 11
I know this is an old post but, I thought I would give some more insight.
If you are trying to use the –-onefile and just make a single file, then simply moving the .kv file to the directory many not be a good options for you.
What I did was embed the .kv file content in the python itself using
from kivy.lang import Builder
Builder.load_string("""
Your kivy content
""")
And moved the main.py
into its own folder and renamed it to something else like main_em.py
before I ran the command
python -m PyInstaller --onefile --windowed --name "myApp" "./main_em.py"
My reason for moving it into a new folder is because if you try and run program as just a python file it will stack two of the same layouts so basically it looks like you have double vision.
The renaming is not really required but, I wanted to keep my code base clean.
Although, I am not 100% sure on this but, I think the PyInstaller doesn’t know how to handle the .kv file so that is why you just have to move it into the folder. But, if you embed it into the python then it is just there in the python code.
It is not really a good practice to have you .kv file embedded in your python code for maintainability but, in this case since you are packaging it up it doesn’t matter.
The way I would handle the work flow is just work on your kviy project like you would otherwise and when it comes time for you to package it. All you need to do is just copy and paste into your main_em.py and run the PyInstaller on the main_em.py.
This way you can stay with the convention and best practice and also not have to move your .kv file into the directory after packaging it. Best of both worlds.
I hope this helps others, this is my first post ever.
Upvotes: 1
Reputation: 2257
I had this same problem and solved it by copying the .kv file to the dist folder.
cp -R C:/Users/Ben/Documents/OpenCV_HummingbirdsMotion/MotionMeerkat/MotionMeerkat.kv dist/main/
This may also be achieved by adding the .kv to the spec file as a data object. Basically the blank screen says, i know there is a kivy app, but i have no widgets.
Upvotes: 1