PyInstaller打包后缺失tls-client-64.dll依赖问题求助
解决Python打包时tls-client-64.dll及其他DLL缺失问题
错误信息
FileNotFoundError: Could not find module 'C:\Users\garfi\AppData\Local\Temp\_MEI200362\tls_client\dependencies\tls-client-64.dll' (or one of its dependencies). Try using the full path with constructor syntax. The above exception was the direct cause of the following exception: Traceback (most recent call last): File "main.py", line 19, in <module> File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module File "tls_client\__init__.py", line 15, in <module> File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module File "tls_client\sessions.py", line 1, in <module> File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module File "tls_client\cffi.py", line 20, in <module> File "ctypes\__init__.py", line 452, in LoadLibrary File "PyInstaller\loader\pyimod03_ctypes.py", line 55, in __init__ pyimod03_ctypes.install.<locals>.PyInstallerImportError: Failed to load dynlib/dll 'C:\\Users\\garfi\\AppData\\Local\\Temp\\_MEI200362\\tls_client/dependencies/tls-client-64.dll'. Most likely this dynlib/dll was not found when the application was frozen. [4520] Failed to execute script 'main' due to unhandled exception!
针对性解决tls-client-64.dll问题
手动指定DLL路径打包
- 找到你Python环境中
tls_client模块的安装路径,比如Lib\site-packages\tls_client\dependencies\tls-client-64.dll。 - 用PyInstaller打包时添加参数,把DLL映射到对应目录:
用auto-py-to-exe的话,在「附加文件」中添加该DLL,设置输出目录为pyinstaller --add-data "你的DLL完整路径;tls_client/dependencies/" main.pytls_client/dependencies/。 - 修改脚本逻辑,确保打包后能正确识别DLL路径:
import os import sys # 打包后会生成临时目录,先指定DLL路径 if hasattr(sys, '_MEIPASS'): dll_path = os.path.join(sys._MEIPASS, 'tls_client', 'dependencies', 'tls-client-64.dll') os.environ['TLS_CLIENT_DLL_PATH'] = dll_path # 再导入tls_client import tls_client
- 找到你Python环境中
切换稳定版本的tls_client
部分新版本存在打包路径识别bug,卸载重装旧版本试试:pip uninstall tls_client -y pip install tls-client==0.2.4
通用DLL缺失排查方案
强制收集模块所有关联文件
用PyInstaller的--collect-all参数,直接把依赖模块的所有文件(包括隐藏DLL)打包:pyinstaller --collect-all tls_client --collect-all aiohttp main.py把你用到的复杂模块(如
whois、qrcode)都添加到参数中。检查DLL深层依赖
用Dependency Walker工具打开tls-client-64.dll,查看是否缺失系统级DLL(如VC运行库)。若缺失,安装对应版本的Visual C Redistributable包,必要时将这些系统DLL也加入打包列表。手动编辑spec文件
自动打包无效时,编辑生成的.spec文件,在datas列表中添加DLL路径:a = Analysis( ['main.py'], datas=[('你的DLL路径', 'tls_client/dependencies')], # 其他参数保持不变 )然后执行
pyinstaller main.spec重新打包。放弃单文件打包模式
单文件打包会将所有文件解压到临时目录,容易出现路径识别问题。改用文件夹打包(去掉--onefile参数),直接把DLL放到打包后的tls_client/dependencies目录中,确保路径匹配。
内容的提问来源于stack exchange,提问作者Uzumaki Yoshie
相关产品推荐
相关产品推荐

