百分百解决python程序通过pyinstaller打包后提示运行库找不到:api-ms-win-core-path-l1-1-0.dll 的问题

问题现象在这里插入图片描述

解决思路

这个问题估计很多人都遇到过,网上我也找了好多教程,但都没有效果,后来我再仔细看打包过程的提示信息:

12575 WARNING: lib not found: api-ms-win-core-path-l1-1-0.dll dependency of D:\Program Files\Python39\python39.dll

这里表达的意思很明显:
D:\Program Files\Python39\目录找不到api-ms-win-core-path-l1-1-0.dll文件,那么解决方法就来了

解决方法

  1. 从网上下载一个api-ms-win-core-path-l1-1-0.dll文件,同理,其他运行库请自己在网上找,或者下载一个dll修复工具
  2. 将下载好的dll文件放在以下目录:

python根目录:D:\Program Files\Python39\
系统运行库目录: C:\Windows\System32\downlevel
保险点可以再自己创建一个dll目录,存放缺失的dll文件

如下:
在这里插入图片描述

实践

1、通过命令指定

然后打包的时候通过-p参数去指定一个运行库目录,例如:

打包命令:
pyinstaller -F -w -i D:\编程学习\python\IP\Client\config\Y.ico -p D:\go\dll -p C:\Windows\System32\downlevel .\gui.py
运行效果:
PS D:\go> pyinstaller -F -w -i D:\编程学习\python\IP\Client\config\Y.ico -p D:\go\dll -p C:\Windows\System32\downlevel .\gui.py
268 INFO: PyInstaller: 4.2
268 INFO: Python: 3.9.2
273 INFO: Platform: Windows-10-10.0.19041-SP0
277 INFO: wrote D:\go\gui.spec
288 INFO: UPX is not available.
298 INFO: Extending PYTHONPATH with paths
['D:\\go', 'D:\\go\\dll', 'C:\\Windows\\System32\\downlevel', 'D:\\go']
318 INFO: checking Analysis
356 INFO: Building because inputs changed
356 INFO: Initializing module dependency graph...
366 INFO: Caching module graph hooks...
381 WARNING: Several hooks defined for module 'win32ctypes.core'. Please take care they do not conflict.
391 INFO: Analyzing base_library.zip ...
4114 INFO: Processing pre-find module path hook distutils from 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller-4.2-py3.9.egg\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
4482 INFO: distutils: retargeting to non-venv dir 'D:\\Program Files\\Python39\\lib'
7834 INFO: Caching module dependency graph...
8004 INFO: running Analysis Analysis-00.toc
8009 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by D:\Program Files\Python39\python.exe
8549 INFO: Analyzing D:\go\gui.py
8772 INFO: Processing pre-safe import module hook urllib3.packages.six.moves from 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller-4.2-py3.9.egg\\PyInstaller\\hooks\\pre_safe_import_module\\hook-urllib3.packages.six.moves.py'.
11398 INFO: Processing module hooks...
11398 INFO: Loading module hook 'hook-certifi.py' from 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller_hooks_contrib-2021.1-py3.9.egg\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
11417 INFO: Loading module hook 'hook-difflib.py' from 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller-4.2-py3.9.egg\\PyInstaller\\hooks'...
11421 INFO: Excluding import of doctest from module difflib
11422 INFO: Loading module hook 'hook-distutils.py' from 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller-4.2-py3.9.egg\\PyInstaller\\hooks'...
11426 INFO: Loading module hook 'hook-distutils.util.py' from 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller-4.2-py3.9.egg\\PyInstaller\\hooks'...
11429 INFO: Excluding import of lib2to3.refactor from module distutils.util
11430 INFO: Loading module hook 'hook-encodings.py' from 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller-4.2-py3.9.egg\\PyInstaller\\hooks'...
11590 INFO: Loading module hook 'hook-heapq.py' from 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller-4.2-py3.9.egg\\PyInstaller\\hooks'...
11594 INFO: Excluding import of doctest from module heapq
11594 INFO: Loading module hook 'hook-lib2to3.py' from 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller-4.2-py3.9.egg\\PyInstaller\\hooks'...
11922 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller-4.2-py3.9.egg\\PyInstaller\\hooks'...
11925 INFO: Excluding import of test from module multiprocessing.util
11926 INFO: Excluding import of test.support from module multiprocessing.util
11928 INFO: Loading module hook 'hook-pickle.py' from 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller-4.2-py3.9.egg\\PyInstaller\\hooks'...
11933 INFO: Excluding import of argparse from module pickle
11936 INFO: Loading module hook 'hook-PIL.Image.py' from 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller-4.2-py3.9.egg\\PyInstaller\\hooks'...
12512 INFO: Loading module hook 'hook-PIL.ImageFilter.py' from 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller-4.2-py3.9.egg\\PyInstaller\\hooks'...
12515 INFO: Excluding import of numpy from module PIL.ImageFilter
12515 INFO: Loading module hook 'hook-PIL.py' from 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller-4.2-py3.9.egg\\PyInstaller\\hooks'...
12523 INFO: Excluding import of PyQt5.QtCore from module PIL.ImageQt
12524 INFO: Excluding import of PyQt5.QtGui from module PIL.ImageQt
12526 INFO: Excluding import of tkinter from module PIL.ImageTk
12527 INFO: Import to be excluded not found: 'FixTk'
12528 INFO: Loading module hook 'hook-PIL.SpiderImagePlugin.py' from 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller-4.2-py3.9.egg\\PyInstaller\\hooks'...
12531 INFO: Import to be excluded not found: 'FixTk'
12531 INFO: Loading module hook 'hook-PyQt5.py' from 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller-4.2-py3.9.egg\\PyInstaller\\hooks'...
12784 WARNING: Hidden import "sip" not found!
12785 INFO: Loading module hook 'hook-PyQt5.QtCore.py' from 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller-4.2-py3.9.egg\\PyInstaller\\hooks'...
12931 INFO: Loading module hook 'hook-PyQt5.QtGui.py' from 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller-4.2-py3.9.egg\\PyInstaller\\hooks'...
13235 INFO: Loading module hook 'hook-sysconfig.py' from 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller-4.2-py3.9.egg\\PyInstaller\\hooks'...
13237 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller-4.2-py3.9.egg\\PyInstaller\\hooks'...
13240 INFO: Loading module hook 'hook-xml.py' from 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller-4.2-py3.9.egg\\PyInstaller\\hooks'...
13310 INFO: Loading module hook 'hook-_tkinter.py' from 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller-4.2-py3.9.egg\\PyInstaller\\hooks'...
13595 INFO: checking Tree
13721 INFO: checking Tree
13919 INFO: checking Tree
13971 INFO: Looking for ctypes DLLs
14008 INFO: Analyzing run-time hooks ...
14013 INFO: Including run-time hook 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller-4.2-py3.9.egg\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
14017 INFO: Including run-time hook 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller_hooks_contrib-2021.1-py3.9.egg\\_pyinstaller_hooks_contrib\\hooks\\rthooks\\pyi_rth_certifi.py'
14020 INFO: Including run-time hook 'D:\\Program Files\\Python39\\lib\\site-packages\\pyinstaller-4.2-py3.9.egg\\PyInstaller\\hooks\\rthooks\\pyi_rth__tkinter.py'
14030 INFO: Looking for dynamic libraries
14465 INFO: Looking for eggs
14465 INFO: Using Python library D:\Program Files\Python39\python39.dll
14471 INFO: Found binding redirects:
[]
14482 INFO: Warnings written to D:\go\build\gui\warn-gui.txt
14561 INFO: Graph cross-reference written to D:\go\build\gui\xref-gui.html
14621 INFO: checking PYZ
14644 INFO: Building because toc changed
14645 INFO: Building PYZ (ZlibArchive) D:\go\build\gui\PYZ-00.pyz
16329 INFO: Building PYZ (ZlibArchive) D:\go\build\gui\PYZ-00.pyz completed successfully.
16354 INFO: checking PKG
16381 INFO: Building because toc changed
16381 INFO: Building PKG (CArchive) PKG-00.pkg
20272 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
20308 INFO: Bootloader D:\Program Files\Python39\lib\site-packages\pyinstaller-4.2-py3.9.egg\PyInstaller\bootloader\Windows-64bit\runw.exe
20309 INFO: checking EXE
20347 INFO: Building because toc changed
20347 INFO: Building EXE from EXE-00.toc
20355 INFO: Copying icons from ['D:\\编程学习\\python\\IP\\Client\\config\\Y.ico']
20453 INFO: Writing RT_GROUP_ICON 0 resource with 20 bytes
20454 INFO: Writing RT_ICON 1 resource with 270376 bytes
20473 INFO: Updating manifest in D:\go\build\gui\runw.exe.wsldvaz_
20552 INFO: Updating resource type 24 name 1 language 0
20558 INFO: Appending archive to EXE D:\go\dist\gui.exe
20657 INFO: Building EXE from EXE-00.toc completed successfully.

此时就没有提示dll的错误了

2、通过编辑spec文件实现

把需要的运行环境目录都添加到pathex列表上

pathex=['D:\\go','C:\\Windows\\System32\\downlevel','D:\\go\\dll'],

在这里插入图片描述
然后通过命令:

 pyinstaller -F .\gui.spec

去打包

实现效果

在这里插入图片描述
可以看到,此时已经不提示dll的错误了,但是提示了pyi_rth_multiprocessing的错误,解决方法看下面这篇:

待更新

总结:

解决问题就要先理解问题,所以同样的,如果提示缺少什么模块、dll文件,只需要找到这些文件,然后通过-p参数去引用即可

**创作不易,转载请注明来源,谢谢**

  • 23
    点赞
  • 63
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 19
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 19
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

坐公交也用券

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值