HaujetZhao / PyInstaller-Perfect-Build-Method

如果我要写一个 Python 项目,打包成 exe 运行(方便在没有 Python 的电脑上使用),我需要打包出的根目录结构美观,没有多余的、杂乱的依赖文件在那里碍眼,而且需要在发现 bug 时,我还需要能够修改里面的代码后,无需再次打包,就能正常运行,该怎么做呢? 就以一个 Hello 项目为例,记一下我找到的完美方法。
97 stars 24 forks source link

添加hook.py后,执行exe时很多dll找不到 #5

Open tankchenggeng opened 1 year ago

tankchenggeng commented 1 year ago

Traceback (most recent call last): File "Lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_win32comgenpy.py", line 40, in File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "win32com__init.py", line 8, in File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "pythoncom.py", line 2, in File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module File "pywintypes.py", line 126, in File "pywintypes.py", line 47, in import_pywin32_system_module__ ImportError: Module 'pywintypes' isn't in frozen sys.path ['D:\Server\Research\ModasPro_KEYAN_SAMPLE\dist\libs', 'D:\Server\Research\ModasPro_KEYAN_SAMPLE\dist\envs', 'D:\Server\Research\ModasPro_KEYAN_SAMPLE\dist\envs\lib-dynload', 'D:\Server\Research\ModasPro_KEYAN_SAMPLE\dist\envs\base_library.zip', 'D:\Server\Research\ModasPro_KEYAN_SAMPLE\dist\base_library.zip', 'D:\Server\Research\ModasPro_KEYAN_SAMPLE\dist\lib-dynload', 'D:\Server\Research\ModasPro_KEYAN_SAMPLE\dist'] [271392] Failed to execute script 'pyi_rth_win32comgenpy' due to unhandled exception!

以这个为例,添加hook.py后,原本存在于pywin32_system32目录下的dll必须手动移出来才找得到

HaujetZhao commented 1 year ago

我也遇到了这个问题,win32 相关的库确实没找到怎么改。等等吧,等过一两个月,预计 Pyinstaller 6.0 就发布了,直接原生支持把杂七杂八汇总到一个文件夹。

blyc commented 1 year ago

Pyinstaller 6.0.0 发布了,确实支持了默认把依赖单独拉到_internal文件夹下 不知道作者会不会基于6.0更新下教程(py外置 和 双exe部分)? ~(虽然已经在基于现有教程尝试自己改了,不过萌新落泪~ (已经模仿者搞定了,谢谢大佬教程