阿秉哥
2021-08-25 11:20
采纳率: 100%
浏览 93
已结题

pyinstaller打包程序在本机运行正常,但在其他电脑上无法运行问题?

环境:win10,python3.8
问题:如题,程序打包后在本机运行正常,但换台机子无法运行。打包时debug设置为True,在两台电脑运行调试结果,可以看出,在其他电脑使用CMD运行调试时,只执行到入口程序就提示“XXX.exe已停止工作,出现了一个问题,导致程序停止工作,如果有可用的解决方案,windows将关闭程序并通知您”。错误提示关闭后,并无其他错误提示,调试代码与正常电脑执行调试是是一样的,没有其他错误,不知道是何原因?

初步排查与win10或win7无关,因为我另一台win7系统(有配置过anaconda环境)也可以正常使用。
本机运行调试代码如下:

D:\setup\cmsdown1.1\dist\cmsmain>cmsmain 
[12068] PyInstaller Bootloader 3.x 
[12068] LOADER: executable is D:\setup\cmsdown1.1\dist\cmsmain\cmsmain.exe 
[12068] LOADER: homepath is D:\setup\cmsdown1.1\dist\cmsmain 
[12068] LOADER: _MEIPASS2 is NULL 
[12068] LOADER: archivename is D:\setup\cmsdown1.1\dist\cmsmain\cmsmain.exe 
[12068] LOADER: No need to extract files to run; setting extractionpath to homepath 
[12068] LOADER: SetDllDirectory(D:\setup\cmsdown1.1\dist\cmsmain) 
[12068] LOADER: Already in the child - running user's code. 
[12068] LOADER: Python library: D:\setup\cmsdown1.1\dist\cmsmain\python38.dll 
[12068] LOADER: Loaded functions from Python library. 
[12068] LOADER: Manipulating environment (sys.path, sys.prefix) 
[12068] LOADER: sys.prefix is D:\setup\cmsdown1.1\dist\cmsmain 
[12068] LOADER: Pre-init sys.path is D:\setup\cmsdown1.1\dist\cmsmain\base_library.zip;D:\setup\cmsdown1.1\dist\cmsmain 
[12068] LOADER: Setting runtime options 
[12068] LOADER: Initializing python 
[12068] LOADER: Overriding Python's sys.path 
[12068] LOADER: Post-init sys.path is D:\setup\cmsdown1.1\dist\cmsmain\base_library.zip;D:\setup\cmsdown1.1\dist\cmsmain 
[12068] LOADER: Setting sys.argv 
[12068] LOADER: setting sys._MEIPASS 
[12068] LOADER: importing modules from CArchive 
[12068] LOADER: extracted struct 
[12068] LOADER: callfunction returned... 
[12068] LOADER: extracted pyimod01_os_path 
[12068] LOADER: callfunction returned... 
[12068] LOADER: extracted pyimod02_archive 
[12068] LOADER: callfunction returned... 
[12068] LOADER: extracted pyimod03_importers 
[12068] LOADER: callfunction returned... 
[12068] LOADER: Installing PYZ archive with Python modules. 
[12068] LOADER: PYZ archive: PYZ-00.pyz 
[12068] LOADER: Running pyiboot01_bootstrap.py 
[12068] LOADER: Running pyi_rth_multiprocessing.py 
[12068] LOADER: Running pyi_rth_pkgres.py 
[12068] LOADER: Running pyi_rth_win32comgenpy.py 
[12068] LOADER: Running pyi_rth__tkinter.py 
[12068] LOADER: Running cms_main.py #此处为打包的入口程序,以下的为其他调用程序。
[12068] LOADER: Running loginPage.py 
[12068] LOADER: Running Browser_os.py 
[12068] LOADER: Running DlPage.py 
[12068] LOADER: Running MainPage.py 
[12068] LOADER: Running frame_downPage.py 
[12068] LOADER: Running Datadown_cms.py 
[12068] LOADER: Running IRBS.py 
[12068] LOADER: Running CallLogger.py 
[12068] LOADER: Running AboutFrame.py 
[12068] LOADER: Running Writer_AutoFit.py 
[12068] LOADER: OK. 
[12068] LOADER: Cleaning up Python interpreter. 

其他电脑运行调试代码如下:

[6552] PyInstaller Bootloader 3.x
[6552] LOADER: executable is D:\cmsmain\cmsmain.exe
[6552] LOADER: homepath is D:\cmsmain
[6552] LOADER: _MEIPASS2 is NULL
[6552] LOADER: archivename is D:\cmsmain\cmsmain.exe
[6552] LOADER: No need to extract files to run; setting extractionpath to homepath
[6552] LOADER: SetDllDirectory(D:\cmsmain)
[6552] LOADER: Already in the child - running user's code.
[6552] LOADER: Python library: D:\cmsmain\python38.dll
[6552] LOADER: Loaded functions from Python library.
[6552] LOADER: Manipulating environment (sys.path, sys.prefix)
[6552] LOADER: sys.prefix is D:\cmsmain
[6552] LOADER: Pre-init sys.path is D:\cmsmain\base_library.zip;D:\cmsmain
[6552] LOADER: Setting runtime options
[6552] LOADER: Initializing python
[6552] LOADER: Overriding Python's sys.path
[6552] LOADER: Post-init sys.path is D:\cmsmain\base_library.zip;D:\cmsmain
[6552] LOADER: Setting sys.argv
[6552] LOADER: setting sys._MEIPASS
[6552] LOADER: importing modules from CArchive
[6552] LOADER: extracted struct
[6552] LOADER: callfunction returned...
[6552] LOADER: extracted pyimod01_os_path
[6552] LOADER: callfunction returned...
[6552] LOADER: extracted pyimod02_archive
[6552] LOADER: callfunction returned...
[6552] LOADER: extracted pyimod03_importers
[6552] LOADER: callfunction returned...
[6552] LOADER: Installing PYZ archive with Python modules.
[6552] LOADER: PYZ archive: PYZ-00.pyz
[6552] LOADER: Running pyiboot01_bootstrap.py
[6552] LOADER: Running pyi_rth_multiprocessing.py
[6552] LOADER: Running pyi_rth_pkgres.py
[6552] LOADER: Running pyi_rth_win32comgenpy.py
[6552] LOADER: Running pyi_rth__tkinter.py
[6552] LOADER: Running cms_main.py #此处为打包的入口程序

调试到此提示错误如下图:
img
程序调用的其他py程序(loginPage.py、Browser_os.py 、DlPage.py、MainPage.py、frame_downPage.py、Datadown_cms.py、IRBS.py、CallLogger.py 、AboutFrame.py、Writer_AutoFit.py)未运行。
本人刚学python不久,请各位指教,谢谢!

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • 阿秉哥 2021-08-26 12:01
    已采纳

    用最土的办法解决:
    问题原因:
    缺少两个dll文件,mkl_core.1.dll 和 mkl_avx2.1.dll,其中,没有mkl_core.1.dll 这个文件,边运行报错都没有,增加这个文件后会提示缺少mkl_avx2.1.dll文件,这两个文件都拷贝到程序目录下后,问题解决。

    问题查找思路:
    使用pyinstaller打包后在其他电脑使用cmd中运行或直接运行主程序文件,提示“程序已停止”的弹窗错误,但在调试窗口没有任何报错信息,导致无从下手。因此在这台电脑上也安装anaconda, 继续使用cmd中运行或直接运行主程序文件,仍然出现同样的弹窗错误,试着用anaconda prompt执行主程序,发现可以正常使用,说明程序大问题没有,应该是使用prompt执行时调用了anaconda程序下的某些文件才能正常运行,因此,试着将这台电脑中系统环境变量中path中的路径逐个删除,采用排队法找到调用文件目录,用这个方法找到了调用anaconda\Library\bin这个目录,因此将这个目录从环境变量path中删除后,将这个目录拷贝至硬盘其他目录,先删除与打包程序中已经有的文件,缩小查找范围,并使用上述查找的方法,逐步删除该文件夹下的内容,找出缺少文件。
    最终发现增加mkl_core.1.dll 和 mkl_avx2.1.dll这两个文件即可解决前述问题。
    对于为什么在使用pyinstaller打包时没有提示错误,就不知道了,如有知道原因的,不吝赐教,可在评论区留言,谢谢。
    在此也感谢黄老师在百忙中帮忙查找原因和提供的解决思路。

    已采纳该答案
    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题