PyQt5 Executable 因缺少 DLL 而崩溃 [英] PyQt5 Executable is crashing with Missing DLL

查看:123
本文介绍了PyQt5 Executable 因缺少 DLL 而崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题与我使用 pyinstaller 创建的 pyqt5 可执行文件有关.我使用的唯一命令是:

pyinstaller script.py

我对 Pyinstaller 的输出消息不是很有经验.所以我发布这个问题以防其他人可以帮助我找出丢失的模块或文件是什么.

这是整个编译输出的副本:

感谢任何评论或帮助.如果您认为自己有可能的解决方案,请尝试回答.我相信它值得研究.希望这很简单,因为我缺乏知识.

另一个注意事项,我正在导入/使用模块 ibm_db 和包装器模块 ibm_db_dbi.

这是我的规范文件的副本:

# -*- 模式:python -*-block_cipher = 无添加的文件 = [(r'C:\Python37\Lib\site-packages\ibm_db_dlls\ibm_db.dll', '.')]a = Analysis(['InheritMainWindow.py'],pathex=['c:\\Python37\\PDFMaker_v3\\Prototype','C:\\Python37\\Lib\\site-packages\\','C:\\Python37\\Lib\\site-packages\\sqlalchemy\\connectors\\','C:\\Python37\\Lib\\site-packages\\clidriver\\','C:\\Python37\\Lib\\site-packages\\ibm_db_dlls','C:\\Python37\\Lib\\site-packages\\ibm_db.py'],二进制文件=[('ibm_db.dll', 'ibm_db_dlls')],数据=[],hiddenimports=['ibm_db', 'ibm_db_dbi'],钩子路径=[],runtime_hooks=[],排除=[],win_no_prefer_redirects=假,win_private_assemblies=假,密码=块密码,noarchive=假)pyz = PYZ(a.pure, a.zipped_data,密码=块_密码)exe = EXE(pyz,a. 脚本,[],exclude_binaries=真,名称='继承主窗口',调试=假,bootloader_ignore_signals=假,条=假,upx=真,控制台=真)a.binaries = [x for x in a.binaries if os.path.dirname(x[1]).find("IBM") <0]科尔 = 收集(exe,a.二进制文件,a.zip 文件,a.数据,条=假,upx=真,名称='继承主窗口')

PS 您应该能够重复以下问题:

导入 ibm_db打印('你好!')

在命令提示符中:

pyinstaller hello.py

在 dist 文件夹中执行 exe 后,您将收到与上述相同的错误.

以下是我尝试解决的问题的列表:

1) 在二进制文件中提供完整路径,如下所示:

binaries=[(r'C:\Python37\Lib\site-packages\ibm_db_dlls\ibm_db.dll', 'ibm_db_dlls')]

这没什么区别,崩溃仍然发生.我已经看到 ibm_db_dlls 文件夹出现在我的 dist 文件夹中.所以正在添加二进制文件,但只是没有被看到.

2) 来自此处的 ibm 开发者论坛:https:///developer.ibm.com/answers/questions/448999/python-3-db2-windows-10-problems-and-script-compil/

建议的解决方案是使用 --clean 选项.我已经在hello.py"上试过这个选项,它只导入 ibm_db 包,它实际上作为一个 exe 工作.但是这个解决方案不适用于我的主要项目.

更正:即使在简单的 hello.py 示例上,这也不起作用.

最终更新:我在下面提供了解决方案!

解决方案

所以我解决了这个问题.我希望这会帮助很多人.解决方案的第一部分是 PATHEX 列表.我必须更新此列表以指向我系统的所有 IBM 目录:

# -*- 模式:python -*-block_cipher = 无a = Analysis(['InheritMainWindow.py'],pathex=['c:\\Python37\\PDFMaker_v3','C:\\Python37\\Lib\\site-packages\\ibm_db_dlls','C:\\Program Files (x86)\\ibm\\gsk8\\lib','C:\\Program Files (x86)\\ibm\\gsk8\\bin','C:\\Program Files (x86)\\IBM Informix Client SDK\\bin','C:\\Program Files (x86)\\IBM\\SQLLIB_01\\BIN','C:\\Program Files (x86)\\IBM\\SQLLIB_01\\FUNCTION','C:\\Program Files (x86)\\IBM\\SQLLIB_01\\BIN','C:\\Program Files (x86)\\IBM\\SQLLIB_01\\FUNCTION','C:\\Program Files (x86)\\ibm\\gsk8\\lib','C:\\Program Files (x86)\\ibm\\gsk8\\bin','C:\\Program Files (x86)\\IBM Informix Client SDK\\bin'],二进制文件=[(r'C:\Python37\Lib\site-packages\ibm_db_dlls\ibm_db.dll', 'ibm_db_dlls')],数据=[],隐藏进口=[],钩子路径=[],runtime_hooks=[],排除=[],win_no_prefer_redirects=假,win_private_assemblies=假,密码=块密码,noarchive=假)pyz = PYZ(a.pure, a.zipped_data,密码=block_cipher)exe = EXE(pyz,a. 脚本,[],exclude_binaries=真,名称='继承主窗口',调试=假,bootloader_ignore_signals=假,条=假,upx=真,控制台=真)科尔 = 收集(exe,a.二进制文件,a.zip 文件,a.数据,条=假,upx=真,名称='继承主窗口')

答案的下一部分很难弄清楚.它在 imb_db.py 文件中找到:

导入操作系统如果 'clidriver' 不在 os.environ['PATH'] 中:os.environ['PATH'] = os.environ['PATH'] + ";"+ os.path.join(os.path.abspath(os.path.dirname(__file__)), 'clidriver', 'bin')定义 __bootstrap__():全局 __bootstrap__、__loader__、__file__导入系统、pkg_resources、imp__file__ = pkg_resources.resource_filename(__name__,'ibm_db_dlls\\ibm_db.dll')__loader__ = 无;del __bootstrap__, __loader__imp.load_dynamic(__name__,__file__)__引导__()

我必须更新我的路径变量以包含 clidriver 目录:

C:\Python37\Lib\site-packages\clidriver\bin

imb_db.py 假设将其添加到路径中,但它以错误的格式或目录添加.这样下一行:

__file__ = pkg_resources.resource_filename(__name__,'ibm_db_dlls\\ibm_db.dll')

最终找不到 .dll 文件.因此,在进行这两个更新后,程序运行并成功连接到远程 DB2 数据库.

My issue is related to a pyqt5 executable I created with pyinstaller. The only command I'm using is:

pyinstaller script.py

I'm not very experienced with Pyinstaller's output messages. So I'm posting this question in case someone else can help me figure out what the missing modules or files are.

Here is copy of the entire Compile output:

Github - Pyinstaller Output

Here is a copy of the error that appears.. it happens like in a millisecond:

Any comments or help are appreciated. If you think you have a possible solution, please attempt an answer. I'm sure its worth looking into. Hopefully, its something simple and due to my lack of knowledge.

One other note, I'm importing/using the module ibm_db and the wrapper module ibm_db_dbi.

Here is a copy of my spec file:

# -*- mode: python -*-

block_cipher = None

added_files = [
                (r'C:\Python37\Lib\site-packages\ibm_db_dlls\ibm_db.dll', '.')
              ]

a = Analysis(['InheritMainWindow.py'],
             pathex=['c:\\Python37\\PDFMaker_v3\\Prototype',
                     'C:\\Python37\\Lib\\site-packages\\',
                     'C:\\Python37\\Lib\\site-packages\\sqlalchemy\\connectors\\',
                     'C:\\Python37\\Lib\\site-packages\\clidriver\\',
                     'C:\\Python37\\Lib\\site-packages\\ibm_db_dlls',
                     'C:\\Python37\\Lib\\site-packages\\ibm_db.py'],
             binaries=[('ibm_db.dll', 'ibm_db_dlls')],
             datas=[],
             hiddenimports=['ibm_db', 'ibm_db_dbi'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='InheritMainWindow',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )

a.binaries = [x for x in a.binaries if os.path.dirname(x[1]).find("IBM") < 0]
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='InheritMainWindow')

PS you should be able to repeat the issue with the following:

import ibm_db
print('hello!')

in command prompt:

pyinstaller hello.py

Upon executing the exe inside the dist folder, you'll get the same above error.

Here is a list of the things I'm tried to resolve this:

1) Providing a full path in the binary like this:

binaries=[(r'C:\Python37\Lib\site-packages\ibm_db_dlls\ibm_db.dll', 'ibm_db_dlls')]

This makes no difference the crash still occurs. And I was already seeing the ibm_db_dlls folder appear in my dist folder. So the binary is being added, but its just not being seen.

2) From the ibm developer forum here: https://developer.ibm.com/answers/questions/448999/python-3-db2-windows-10-problems-and-script-compil/

A suggested solution was using the --clean option. I've tried this option on 'hello.py', where it only is importing the ibm_db package and it actually works as an exe. But this solution doesn't work on my main project.

Correction: This does NOT work even on the simple hello.py example.

Final update: I've provided a solution below!

解决方案

So I solved the issue. And I'm expecting this should help a lot of folks. First part of solution is the PATHEX list. I had to update this list to point to all my system's IBM directories:

# -*- mode: python -*-

block_cipher = None


a = Analysis(['InheritMainWindow.py'],
             pathex=['c:\\Python37\\PDFMaker_v3',
                     'C:\\Python37\\Lib\\site-packages\\ibm_db_dlls',
                     'C:\\Program Files (x86)\\ibm\\gsk8\\lib', 
                     'C:\\Program Files (x86)\\ibm\\gsk8\\bin', 
                     'C:\\Program Files (x86)\\IBM Informix Client SDK\\bin', 
                     'C:\\Program Files (x86)\\IBM\\SQLLIB_01\\BIN', 
                     'C:\\Program Files (x86)\\IBM\\SQLLIB_01\\FUNCTION', 
                     'C:\\Program Files (x86)\\IBM\\SQLLIB_01\\BIN', 
                     'C:\\Program Files (x86)\\IBM\\SQLLIB_01\\FUNCTION', 
                     'C:\\Program Files (x86)\\ibm\\gsk8\\lib', 
                     'C:\\Program Files (x86)\\ibm\\gsk8\\bin', 
                     'C:\\Program Files (x86)\\IBM Informix Client SDK\\bin'],
             binaries=[(r'C:\Python37\Lib\site-packages\ibm_db_dlls\ibm_db.dll', 'ibm_db_dlls')],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='InheritMainWindow',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='InheritMainWindow')

The next part of the answer was really tricky in figuring out. Its found inside the imb_db.py file:

import os

if 'clidriver' not in os.environ['PATH']:
    os.environ['PATH'] = os.environ['PATH'] + ";" + os.path.join(os.path.abspath(os.path.dirname(__file__)), 'clidriver', 'bin')  
def __bootstrap__():
   global __bootstrap__, __loader__, __file__
   import sys, pkg_resources, imp
   __file__ = pkg_resources.resource_filename(__name__,'ibm_db_dlls\\ibm_db.dll')
   __loader__ = None; del __bootstrap__, __loader__
   imp.load_dynamic(__name__,__file__)
__bootstrap__()

I had to update my path variable to include clidriver directory:

C:\Python37\Lib\site-packages\clidriver\bin

the imb_db.py is suppose to be adding this to the path, but its adding in in the wrong format or directory. So that the next line:

__file__ = pkg_resources.resource_filename(__name__,'ibm_db_dlls\\ibm_db.dll')

Ends up not finding the .dll file. So after making these two updates, the program runs and succesfully connects to a remote DB2 database.

这篇关于PyQt5 Executable 因缺少 DLL 而崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆