Using pyinstaller to package python program and there is a "NoModuleFoundError"

Question:

I use pyinstaller to package my python program into an executable program(exe).

my programs versions:

Pyinstaller :3.3.1

Python :3.6.1
Windows:10-10.0.16299-SP0


I can run the data_processing_gui.py file with the command "python data_processing_gui.py" in my command-line window without any errors.


I used this command to package my python program (which its name is data_processing_gui.py):

pyinstaller -F -p C:UsersfanyuAnaconda3Lib;C:UsersfanyuAnaconda3Libsite-packages;C:UsersfanyuAnaconda3Libsite-packagesPyQt5Qtbin;C:UsersfanyuAnaconda3Libsite-packagespydicom;C:UsersfanyuAnaconda3Libsite-packagesradiomics;C:UsersfanyuAnaconda3Libsite-packagespywt;C:UsersfanyuAnaconda3Libsite-packagespywt_extensions;C:UsersfanyuAnaconda3Libsite-packagestensorflow;C:UsersfanyuAnaconda3Libsite-packagesSimpleITK;C:UsersfanyuAnaconda3Libsite-packagesPIL;C:UsersfanyuAnaconda3Libsite-packagespandas;C:UsersfanyuAnaconda3Libsite-packagesnrrd;C:UsersfanyuAnaconda3Libsite-packagesnumpy -i C:UsersfanyuDesktopworkpackageimagedoctor.ico data_processing_gui.py

There is no error when I run code above in windows’ command-line window, but when I run the target program(data_progressing_gui.exe), there is a ModuleNotFoundError, and the error information is:

Traceback (most recent call last): File "data_processing_gui.py",
line 12, in File
"c:usersfanyuanaconda3libsite-packagesPyInstallerloaderpyimod03_importers.py",
line 631, in exec_module
exec(bytecode, module.dict) File "site-packagesradiomics_init_.py", line 15, in File
"c:usersfanyuanaconda3libsite-packagesPyInstallerloaderpyimod03_importers.py",
line 631, in exec_module
exec(bytecode, module.dict) File "site-packagesradiomicsimageoperations.py", line 6, in
File
"c:usersfanyuanaconda3libsite-packagesPyInstallerloaderpyimod03_importers.py",
line 631, in exec_module
exec(bytecode, module.dict) File "site-packagespywt_init_.py", line 17, in File
"c:usersfanyuanaconda3libsite-packagesPyInstallerloaderpyimod03_importers.py",
line 631, in exec_module
exec(bytecode, module.dict) File "site-packagespywt_functions.py", line 17, in File
"c:usersfanyuanaconda3libsite-packagesPyInstallerloaderpyimod03_importers.py",
line 714, in load_module
module = loader.load_module(fullname) File "pywt/_extensions/_pywt.pyx", line 1, in init pywt._extensions._pywt
(pywt_extensions_pywt.c:31281) ModuleNotFoundError: No module named
‘pywt._extensions._cwt’ [7564] Failed to execute script
data_processing_gui

It seems like the program can’t find the specified package path (pywt._extensions._cwt), however, I’ve added the path in the pyinstaller’s parameter list.

At first, I thought maybe there was something wrong with my pyinstaller, so I tried to reinstall it. Then I write a simple python program to test it, it runs correctly.

I’ve tried a lot but just can’t solve it, so I am here to ask for help,I will appreciate it if anyone can give me any advice.

Asked By: yongchun zha

||

Answers:

I find a solution for my problem in the answers to the following question ModuleNotFoundError: No module named 'pandas._libs.tslibs.timedeltas'

I can’t explain why but it does solve my problem.

The solution is:
After generating the “.spec” file using pyinstaller,add the missing module into the “.spec” file at “hiddenimport=[]”,like this:

hiddenimport=["pywt","pywt._estentions._cwt"]

Then use this file to generate your exe file:

pyinstaller my.spec
Answered By: yongchun zha
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.