PyInstaller Kivy ClockApp Example Issue

為{幸葍}努か 提交于 2019-12-10 23:59:57

问题


===Edit End===

Whew!

Thanks to the suggestions below & (8) hours of compiling & recompiling I was able to fix my issues doing a combination of things:

  1. Understanding how Pyinstaller hooks are required in order to call out the modules correctly.

  2. Ensuring that all input file & output file file locations exist on the same drive. At my company, our system environment variables are set to a mapped network drive by default, I had to ensure all user environment variable settings were mapped to 'C:\' by default such that pyinstaller would pick it up. This included setting my cmd.exe to the correct drive & destination file output.

  3. Ensuring all necessary files (.JPG, .kv, .PNG) files were in the /dist folder AFTER I built the correct .spec file

I was able to package the PongGame example on the kivy website as well as the Paint_App example for the Book/Chapter 2 mentioned below.

Thanks again.

===LAST Edit End===

===EDIT Again===

According to suggestion below, I've attempted to run program showing the error log.

However, running from cmd.exe doesn't even spit out the error log.

However, .kivy keeps all the error logs.

[INFO              ] Logger: Record log in H:\.kivy\logs\kivy_16-08-30_29.txt
[INFO              ] Kivy: v1.9.1
[INFO              ] Python: v3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit (Intel)]
[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 <b'4.2.0'>
[INFO              ] GL: OpenGL vendor <b'NVIDIA Corporation'>
[INFO              ] GL: OpenGL renderer <b'Quadro K3000M/PCIe/SSE2'>
[INFO              ] GL: OpenGL parsed version: 4, 2
[INFO              ] GL: Shading version <b'4.20 NVIDIA via Cg compiler'>
[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              ] Base: Start application main loop
[INFO              ] Base: Leaving application in progress...
[WARNING           ] stderr: Traceback (most recent call last):
[WARNING           ] stderr:   File "kivy\properties.pyx", line 754, in kivy.properties.ObservableDict.__getattr__ (kivy\properties.c:11776)
[WARNING           ] stderr: KeyError: 'time'
[WARNING           ] stderr: 
[WARNING           ] stderr: During handling of the above exception, another exception occurred:
[WARNING           ] stderr: 
[WARNING           ] stderr: Traceback (most recent call last):
[WARNING           ] stderr:   File "mainClock.py", line 40, in <module>
[WARNING           ] stderr:   File "site-packages\kivy\app.py", line 828, in run
[WARNING           ] stderr:   File "site-packages\kivy\base.py", line 487, in runTouchApp
[WARNING           ] stderr:   File "site-packages\kivy\core\window\window_sdl2.py", line 619, in mainloop
[WARNING           ] stderr:   File "site-packages\kivy\core\window\window_sdl2.py", line 362, in _mainloop
[WARNING           ] stderr:   File "site-packages\kivy\base.py", line 327, in idle
[WARNING           ] stderr:   File "site-packages\kivy\clock.py", line 515, in tick
[WARNING           ] stderr:   File "site-packages\kivy\clock.py", line 647, in _process_events
[WARNING           ] stderr:   File "site-packages\kivy\clock.py", line 406, in tick
[WARNING           ] stderr:   File "mainClock.py", line 32, in update
[WARNING           ] stderr:   File "kivy\properties.pyx", line 757, in kivy.properties.ObservableDict.__getattr__ (kivy\properties.c:11882)
[WARNING           ] stderr: AttributeError: 'super' object has no attribute '__getattr__'

===EDIT AGAIN End===

EDIT:

Looking in the build folder, I see a warnmainClock.txt with a ridiculously LARGE number of lines saying I'm missing modules.

Does this mean I'm not linking to my python folder library correctly?

For example:

missing module named _collections.deque - imported by _collections, collections, threading, C:\Python34x86\Examples\kivy\mainClock.py
missing module named _thread.stack_size - imported by _thread, threading, C:\Python34x86\Examples\kivy\mainClock.py
missing module named _thread._local - imported by _thread, threading, C:\Python34x86\Examples\kivy\mainClock.py
missing module named threading.current_thread - imported by threading, _threading_local, C:\Python34x86\Examples\kivy\mainClock.py
missing module named threading.RLock - imported by threading, _threading_local, bz2, multiprocessing.dummy, C:\Python34x86\Examples\kivy\mainClock.py
missing module named sys.modules - imported by sys, dummy_threading, C:\Python34x86\Examples\kivy\mainClock.py
missing module named _dummy_threading - imported by dummy_threading, C:\Python34x86\Examples\kivy\mainClock.py
missing module named _dummy_threading.__all__ - imported by _dummy_threading, dummy_threading, C:\Python34x86\Examples\kivy\mainClock.py
missing module named dummy_threading.RLock - imported by dummy_threading, bz2, C:\Python34x86\Examples\kivy\mainClock.py
missing module named dummy_threading.local - imported by dummy_threading, numpy.distutils.misc_util, C:\Python34x86\Examples\kivy\mainClock.py
missing module named time.monotonic - imported by time, subprocess, threading, queue, C:\Python34x86\Examples\kivy\mainClock.py
missing module named time.time - imported by time, subprocess, threading, queue, kivy.uix.behaviors.button, kivy.uix.behaviors.compoundselection, kivy.effects.kinetic, kivy.uix.filechooser, kivy.input.motionevent, kivy.input.postproc.doubletap, kivy.input.postproc.tripletap, multiprocessing.managers, multiprocessing.synchronize, C:\Python34x86\Examples\kivy\mainClock.py
missing module named Queue - imported by kivy.compat, C:\Python34x86\Examples\kivy\mainClock.py
missing module named time.strftime - imported by time, kivy.logger, C:\Python34x86\Examples\kivy\mainClock.py
missing module named kivy.app.App - imported by kivy.app, kivy.uix.scrollview, kivy.uix.screenmanager, kivy.uix.filechooser, kivy.uix.textinput, kivy.uix.settings, kivy.lang, kivy.support, kivy.core.window.window_sdl2, kivy.uix.video, kivy.uix.carousel, kivy.uix.treeview, kivy.uix.colorpicker, kivy.uix.splitter, kivy.uix.slider, kivy.uix.codeinput, C:\Python34x86\Examples\kivy\mainClock.py

EDIT END

I am currently learning Kivy from the book "Kivy Blueprints" by Mark Vasilkov.

I am attempting to package the ClockApp from chapter 1 as an exercise. The code works perfectly from python command line. However, I am running into an issue using pyinstaller to create a windows package.

The source code & .kv file is found here https://github.com/mvasilkov/kb/tree/master/1_Clock

I have followed the example https://kivy.org/docs/guide/packaging-windows.html

I created a windows package from the command prompt using:

C:\Python34x86\Scripts\pysintaller C:\Python34x86\Examples\kivy\mainClock.py --noconsole

Then I build from the spec file using:

C:\Python34x86\Scripts\pyinstaller H:\mainClock.spec

Both commands create the /dist file in my H drive as specified.

When I access the EXE file after just building from the \mainClock.py, I get the error:

When I run the EXE file after building the .spec file I get the following:

The .spec file looks like this:

# -*- mode: python -*-

block_cipher = None


a = Analysis(['C:\\Python34x86\\Examples\\kivy\\mainClock.py'],
             pathex=['H:\\'],
             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='mainClock',
          debug=True,
          strip=False,
          upx=True,
          console=False )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='mainClock')

I think the issue isn't stemming from the source, can someone please point out what am I doing incorrectly?


回答1:


May be the following code can help you further?

# -*- 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 = []

# list of modules to exclude from analysis
excludes = ['Tkinter', '_tkinter', 'twisted', '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 = []
assets_toc = [kivy_assets_toc, source_assets_toc]

tocs = bin_tocs + assets_toc


a = Analysis(['C:\\Python34x86\\Examples\\kivy\\mainClock.py'],
             pathex=['H:\\'],
             binaries=None,
             datas=datas,
             hiddenimports=hiddenimports,
             hookspath=[],
             runtime_hooks=[],
             excludes=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,
          name='mainClock',
          exclude_binaries=True,
          debug=False,
          strip=False,
          upx=True,
          console=False)

coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               *tocs,
               strip=False,
               upx=True,
               name='mainClock')


来源:https://stackoverflow.com/questions/39092113/pyinstaller-kivy-clockapp-example-issue

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