简体   繁体   English

pyinstaller转exe后无法导入模块

[英]Cannot import module after turning into exe with pyinstaller

I have compiled my python code to .exe using pyinstaller with the command:我已经使用 pyinstaller 和命令将我的 python 代码编译为 .exe:

pyinstaller --onefile .\mycode.py

It finished without errors but when I try to use the .exe it it gives me the error:它完成时没有错误,但是当我尝试使用 .exe 时,它​​给了我错误:

RuntimeError: Cannot import module **** which is needed to continue

while *** is a module that is definitly installed (when i run mycode.py using python it works fine) and of course is imported in the code.而 *** 是一个明确安装的模块(当我使用 python 运行 mycode.py 时它工作正常),当然是在代码中导入的。 how can i fix it?我该如何解决? Thanks for the helpers.感谢帮助者。

As the comment on the question from the OP says, they were using importlib .正如 OP 对问题的评论所说,他们正在使用importlib PyInstaller can only read imports using the from *** import *** or the import *** format. PyInstaller 只能使用from *** import ***import ***格式读取import *** If you'd like to use importlib , __import__ or any other unsupported method, please add the imports to hiddenimports with the --hidden-import=*** option.如果您想使用importlib__import__或任何其他不受支持的方法,请使用--hidden-import=***选项--hidden-import=***添加到 hiddenimports 中。 This option can be used multiple times.此选项可以多次使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM