PyInstaller .exe文件提前终止,没有错误消息 [英] PyInstaller .exe file terminates early without an error message

查看:212
本文介绍了PyInstaller .exe文件提前终止,没有错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用PyInstaller将我的程序作为捆绑的.exe文件分发给我的同事.该程序分析文本数据,可以从我的CMD完美运行.我使用PyInstaller 3.6,Python 3.7,Windows 10和Anaconda3作为我的python环境.该程序有很多依赖项,包括nltk,gensim,wordcloud,sklearn,matplotlib,mpld3,seaborn,pandas,numpy,xlsxwriter和一些标准库.这也是一个很长的程序,大约2000行.

I have been trying to use PyInstaller to distribute my program as a bundled .exe file to my colleagues. The program, which analyses text data, runs perfectly from my CMD. I am using PyInstaller 3.6, Python 3.7, Windows 10, and Anaconda3 as my python environment. The program has quite a few dependencies including nltk, gensim, wordcloud, sklearn, matplotlib, mpld3, seaborn, pandas, numpy, xlsxwriter and a few standard libraries. It is also quite a long program, ~2000 lines.

问题: 到目前为止,我已经成功构建了.exe文件(作为一个文件夹和一个文件的捆绑包).要测试.exe文件是否有效,我从CMD运行它.一切顺利(我的导入和功能运行正常,系统提示我输入包含文本数据的Excel文件的名称,清除文本等),但是在使用以下命令的行上,它突然终止,而没有任何警告或错误消息Gensim的SparseTermSimilarityMatrix函数.我通过注释掉这一行进行了实验,它终止于下一行,再次没有任何消息.

The Problem: So far, I've successfully built the .exe file (as a one-folder and one-file bundle). To test whether the .exe file works, I run it from my CMD. All is going well (my imports and functions run OK, I am prompted to enter the name of the Excel file containing text data, the text is cleaned etc) but it abruptly terminates, without any warning or error message, on a line that uses Gensim's SparseTermSimilarityMatrix function. I experimented by commenting out this line and it terminates on the very next line, again without any message.

我正在使用.spec文件构建.exe文件(以便可以将数据文件添加到我的捆绑包和几个隐藏的导入中,以克服找不到模块"错误).关于导致此问题的原因的唯一指示是在构建期间有关缺少DLL的警告:

I am building the .exe file using a .spec file (so that I can add data files to my bundle and several hidden imports to overcome Module Not Found Errors). The only indication I have as to what is causing this problem are warnings about missing DLLs during build-time:

108890 INFO: Looking for dynamic libraries
109047 WARNING: lib not found: msmpi.dll dependency of C:\Users\username\anaconda3\envs\pyexe\Library\bin\mkl_blacs_msmpi_lp64.dll
109293 WARNING: lib not found: impi.dll dependency of C:\Users\username\anaconda3\envs\pyexe\Library\bin\mkl_blacs_intelmpi_lp64.dll
109304 WARNING: lib not found: impi.dll dependency of C:\Users\username\anaconda3\envs\pyexe\Library\bin\mkl_blacs_intelmpi_ilp64.dll
109704 WARNING: lib not found: mpich2mpi.dll dependency of C:\Users\username\anaconda3\envs\pyexe\Library\bin\mkl_blacs_mpich2_lp64.dll
109754 WARNING: lib not found: pgc14.dll dependency of C:\Users\username\anaconda3\envs\pyexe\Library\bin\mkl_pgi_thread.dll
109757 WARNING: lib not found: pgf90rtl.dll dependency of C:\Users\username\anaconda3\envs\pyexe\Library\bin\mkl_pgi_thread.dll
109761 WARNING: lib not found: pgf90.dll dependency of C:\Users\username\anaconda3\envs\pyexe\Library\bin\mkl_pgi_thread.dll
110120 WARNING: lib not found: msmpi.dll dependency of C:\Users\username\anaconda3\envs\pyexe\Library\bin\mkl_blacs_msmpi_ilp64.dll
110164 WARNING: lib not found: mpich2mpi.dll dependency of C:\Users\username\anaconda3\envs\pyexe\Library\bin\mkl_blacs_mpich2_ilp64.dll
112452 WARNING: lib not found: icuuc53.dll dependency of C:\Users\username\anaconda3\envs\pyexe\Scripts\Qt5Core.dll
112459 WARNING: lib not found: icuin53.dll dependency of C:\Users\username\anaconda3\envs\pyexe\Scripts\Qt5Core.dll

如果有人能解释一下,我将不胜感激.

1..为什么PyInstaller构建的.exe文件可能会提前终止而没有错误消息-即使在CMD中也如此?

1. Why a PyInstaller-built .exe file might terminate early without an error message - even in CMD?

2..如何解决丢失的DLL(实际上在我的计算机上找不到)?

2. How to address missing DLLs (which indeed I cannot find on my computer)?

更新:如果我首先激活conda环境,则将从CMD成功运行.exe文件! conda activate [myenv] 但是,这违背了独立发行版的目的.

UPDATE: the .exe file successfully runs from the CMD if I first activate my conda environment! conda activate [myenv] However, this defeats the purpose of a standalone distribution.

推荐答案

如果我首先激活anaconda环境,则从我的CMD成功运行.exe文件后,这是我的原始解决方案,该解决方案仅适用于单文件夹捆绑包:

After realising the .exe file successfully runs from my CMD if I first activate my anaconda environment, here was my original solution, which was only suitable for a one-folder bundle:

我从anaconda环境的根目录中搜索了所有"dll"文件(返回很多).我将搜索返回的所有DLL文件复制到了"dist"目录中.我捆绑包的文件夹中,跳过重复项.

From the root directory of my anaconda environment, I searched for all "dll" files (which returns a lot). I copied all DLL files returned by the search to the "dist" folder of my bundle, skipping duplicates.

.exe文件不再提前终止并且可以正常运行!

The .exe file no longer terminated early and worked perfectly!

似乎我在构建期间收到有关缺少DLL的警告具有误导性-引用的DLL文件仍然不在我的计算机上.

It seems that the warnings I received about missing DLLs during build-time were misleading - the DLL files quoted are still not on my computer.

解决方案更新:在将所有DLL文件从anaconda环境手动复制到捆绑包的dist文件夹后,我进行了以下实验:删除每个手动添加的DLL文件并测试.exe是否文件仍然可以像以前一样正常工作或终止. 它归结为一个DLL文件:libiomp5md.dll -实际上,这是缺少的链接!因此,我的建议:

SOLUTION UPDATE: After manually copying all DLL files from my anaconda environment to the dist folder of my bundle, I experimented by removing each DLL file I manually added one by one and testing whether the .exe file still worked or terminated early as before. It came down to just one DLL file: libiomp5md.dll - this was, quite literally, the missing link! Therefore, my recommendation:

  1. 搜索"libiomp5md.dll";在anaconda环境中,然后将其复制到包含.spec文件的目录中.
  2. 将其作为数据文件添加到您的.spec文件中,并指定应将其存储在包的根目录中:datas=[('libiomp5md.dll', '.')]
  3. 使用.spec文件(作为一个文件夹或一个文件包)构建可执行文件!

我希望这能帮助面临类似DLL相关问题的任何人.

I hope this helps anyone facing similar DLL-related issues.

这篇关于PyInstaller .exe文件提前终止,没有错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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