使用pyinstaller 打包python小程序,本地运行正常,copy到新机上,报错,ImportError: DLL load failed while importing win32api: 找不到指定的程序。
卸载pywin32,重装,切换环境,打包结果依然报错,我了个去。
在PowerShell下运行以下代码,完全正常,说明包安装没问题。
import win32api
import win32gui
将DLL复制到system32目录下,问题依旧。问题定位在pywin32未打包到exe中,尝试pyinstaller各种参数,依然无法解决。
最后,在python环境的Scripts目录下,找到pywin32_postinstall.py,运行以下代码后,问题解决
python pywin32_postinstall.py -install
打开pywin32_postinstall.py,找到install函数,增加路径,配置注册表,复制文件,一系列操作,说明pyinstaller安装的时候,没有找到对应路径信息,导致打包的时候却少文件,以此留查。
def install(lib_dir):
import traceback
# The .pth file is now installed as a regular file.
# Create the .pth file in the site-packages dir, and