简体   繁体   English

pyinstaller exe 黑屏

[英]pyinstaller exe blank screen

I've built a .exe on Windows 10 using PyInstaller.我已经使用 PyInstaller 在 Windows 10 上构建了一个 .exe。 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.在 Kivy 1.9.1 中使用 python 2.7 (Enthought Canopy)。 When I run the original source file, everything works perfectly;当我运行原始源文件时,一切正常; it's only the .exe that fails.只有 .exe 失败了。

My .spec file looks like this:我的 .spec 文件如下所示:

# -*- 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

I had this same problem and solved it by copying the .kv file to the dist folder.我遇到了同样的问题,并通过将 .kv 文件复制到 dist 文件夹来解决它。

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.这也可以通过将 .kv 作为数据对象添加到规范文件来实现。 Basically the blank screen says, i know there is a kivy app, but i have no widgets.基本上空白屏幕说,我知道有一个 kivy 应用程序,但我没有小部件。

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.如果您尝试使用 --onefile 并且只制作一个文件,那么简单地将 .kv 文件移动到目录中,这对您来说不是一个好的选择。

What I did was embed the .kv file content in the python itself using我所做的是使用将 .kv 文件内容嵌入到 python 本身中

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并将main.py移动到它自己的文件夹中,并在运行命令之前将其重命名为main_em.py其他内容

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.我将它移动到一个新文件夹的原因是因为如果你尝试将程序作为一个 python 文件运行,它会堆叠两个相同的布局,所以基本上看起来你有双重视觉。

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.虽然,我对此不是 100% 确定,但是,我认为 PyInstaller 不知道如何处理 .kv 文件,因此您只需将其移动到文件夹中即可。 But, if you embed it into the python then it is just there in the python code.但是,如果你将它嵌入到 python 中,那么它就在 python 代码中。

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.为了可维护性,将 .kv 文件嵌入到 Python 代码中并不是一个很好的做法,但是在这种情况下,因为你正在打包它并不重要。

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.我处理工作流程的方式只是在您的 kviy 项目上工作,就像您在其他情况下一样,以及在您打包它的时候。 All you need to do is just copy and paste into your main_em.py and run the PyInstaller on the main_em.py.您需要做的只是复制并粘贴到 main_em.py 中,然后在 main_em.py 上运行 PyInstaller。

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.这样您就可以遵守约定和最佳实践,并且不必在打包后将 .kv 文件移动到目录中。 Best of both worlds.两全其美。

I hope this helps others, this is my first post ever.我希望这可以帮助其他人,这是我的第一篇文章。

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.请记住,如果是从 python 运行它,则必须注释掉 Builder.load_file 行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM