简体   繁体   中英

Cannot import module after turning into exe with pyinstaller

I have compiled my python code to .exe using pyinstaller with the command:

pyinstaller --onefile .\mycode.py

It finished without errors but when I try to use the .exe it it gives me the error:

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. how can i fix it? Thanks for the helpers.

As the comment on the question from the OP says, they were using importlib . PyInstaller can only read imports using the from *** import *** or the import *** format. If you'd like to use importlib , __import__ or any other unsupported method, please add the imports to hiddenimports with the --hidden-import=*** option. This option can be used multiple times.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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