使用pyinstaller 打包后的python 程序,执行的时候出现 "importlib.metadata.PackageNotFoundError" 异常
Traceback (most recent call last):
File "main.py", line 5, in <module>
File "PyInstaller/loader/pyimod02_importers.py", line 352, in exec_module
File "util/convert.py", line 12, in <module>
File "PyInstaller/loader/pyimod02_importers.py", line 352, in exec_module
File "whisper/__init__.py", line 12, in <module>
File "PyInstaller/loader/pyimod02_importers.py", line 352, in exec_module
File "whisper/decoding.py", line 11, in <module>
File "PyInstaller/loader/pyimod02_importers.py", line 352, in exec_module
File "whisper/tokenizer.py", line 8, in <module>
File "PyInstaller/loader/pyimod02_importers.py", line 352, in exec_module
File "transformers/__init__.py", line 30, in <module>
File "PyInstaller/loader/pyimod02_importers.py", line 352, in exec_module
File "transformers/dependency_versions_check.py", line 41, in <module>
File "transformers/utils/versions.py", line 123, in require_version_core
File "transformers/utils/versions.py", line 110, in require_version
importlib.metadata.PackageNotFoundError: No package metadata was found for The 'regex!=2019.12.17' distribution was not found and is required by this application.
Try: pip install transformers -U or pip install -e '.[dev]' if you're working with git main
因为有些依赖包是间接在其他包里被调用,用pyinstaller 打包的时候默认不会包括这些间接调用的依赖包进去,所以我们可以使用 参数 --copy-metadata 手动添加模块的打包,例如 --copy-metadata tqdm 。
pyinstaller main.py --clean -F -c --noconsole --copy-metadata tqdm --copy-metadata regex \ --copy-metadata requests --copy-metadata packaging --copy-metadata filelock