using pyinstaller to package python program and there is a “NoModuleFindError”

别等时光非礼了梦想. 提交于 2019-12-25 02:22:21

问题


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

my program version:

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 ERROR.


I use the command to package my python program(which name is data_processing_gui.py):

pyinstaller -F -p C:\Users\fanyu\Anaconda3\Lib;C:\Users\fanyu\Anaconda3\Lib\site-packages;C:\Users\fanyu\Anaconda3\Lib\site-packages\PyQt5\Qt\bin;C:\Users\fanyu\Anaconda3\Lib\site-packages\pydicom;C:\Users\fanyu\Anaconda3\Lib\site-packages\radiomics;C:\Users\fanyu\Anaconda3\Lib\site-packages\pywt;C:\Users\fanyu\Anaconda3\Lib\site-packages\pywt\_extensions;C:\Users\fanyu\Anaconda3\Lib\site-packages\tensorflow;C:\Users\fanyu\Anaconda3\Lib\site-packages\SimpleITK;C:\Users\fanyu\Anaconda3\Lib\site-packages\PIL;C:\Users\fanyu\Anaconda3\Lib\site-packages\pandas;C:\Users\fanyu\Anaconda3\Lib\site-packages\nrrd;C:\Users\fanyu\Anaconda3\Lib\site-packages\numpy -i C:\Users\fanyu\Desktop\work\package\image\doctor.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 ModuleNotFindError ,the error infomation is:

Traceback (most recent call last): File "data_processing_gui.py", line 12, in File "c:\users\fanyu\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module exec(bytecode, module.dict) File "site-packages\radiomics__init__.py", line 15, in File "c:\users\fanyu\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module exec(bytecode, module.dict) File "site-packages\radiomics\imageoperations.py", line 6, in
File "c:\users\fanyu\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module exec(bytecode, module.dict) File "site-packages\pywt__init__.py", line 17, in File "c:\users\fanyu\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module exec(bytecode, module.dict) File "site-packages\pywt_functions.py", line 17, in File "c:\users\fanyu\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_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 specify package path(pywt._extensions._cwt),however,I've added the path in the pyinstaller's parameter list.

At first,I think maybe there is something wrong with my pyinstaller,so I've 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 any advice.


回答1:


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


来源:https://stackoverflow.com/questions/49232117/using-pyinstaller-to-package-python-program-and-there-is-a-nomodulefinderror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!