I converted the py script to exe using pyinstaller but when I try to run the exe I got this. How can I fix it?
您必须告诉 pyinstaller 需要在程序中捆绑哪些模块,因此,在您的情况下,您必须将其作为隐藏导入传递:pkg_resources
在运行 pyinstaller 后生成的 .spec 文件中,您将找到如下选项:
hiddenimports=[]
像这样说:
hiddenimports=["pkg_resources"]
然后,像这样运行 pyinstaller:
pyinstaller app.spec
或者,如果您仍然想通过 .py 运行它,请将其作为参数传递,例如
pyinstaller app.py --hidden-import pkg_resources
通常,如果您的程序不仅仅是一个“Hello world”,那么这将是更多的模块,您只需将它们全部添加到hiddenimports作为列表,直到没有更多的模块ModuleNotFoundError
.
记得不运行 pyinstaller 到 .py 文件如果您修改了 .spec 文件,因为它将创建一个新文件并覆盖它,忽略前一个文件。
您必须使用 .spec 文件执行 pyinstaller
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)