使用pyinstaller打包python程序,出现“NoModuleFindError"; [英] Using pyinstaller to package python program and there is a "NoModuleFindError"

查看:61
本文介绍了使用pyinstaller打包python程序,出现“NoModuleFindError";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用pyinstaller将我的python程序打包成可执行程序(exe).

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

我的程序版本:

pyinstaller :3.3.1

Pyinstaller :3.3.1

Python :3.6.1视窗:10-10.0.16299-SP0

Python :3.6.1 Windows:10-10.0.16299-SP0

我可以在命令行窗口中使用命令python data_processing_gui.py"运行 data_processing_gui.py 文件而没有任何错误.

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.

我使用命令打包我的python程序(名称为data_processing_gui.py):

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

<小时>

在windows的命令行窗口中运行上面的代码时没有错误,但是当我运行目标程序(data_progressing_gui.exe)时,有一个ModuleNotFindError,错误信息是:

回溯(最近一次调用最后一次):文件data_processing_gui.py",第 12 行,在文件中"c:\users\fanyu\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",第 631 行,在 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",第 631 行,在 exec_module 中exec(bytecode, module.dict) 文件site-packages\radiomics\imageoperations.py",第 6 行,
文件"c:\users\fanyu\anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py",第 631 行,在 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",第 631 行,在 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",第 714 行,在 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] 无法执行脚本data_processing_gui

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

好像程序找不到指定的包路径(pywt._extensions._cwt),不过我已经在pyinstaller的参数列表中添加了路径.

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.

一开始,我想我的pyinstaller可能有问题,所以我尝试重新安装它.然后我写了一个简单的python程序来测试,运行正常.

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.

推荐答案

我在以下问题的答案中找到了解决方案 ModuleNotFoundError:没有名为pandas._libs.tslibs.timedeltas"的模块

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.

解决办法是:使用pyinstaller生成.spec"文件后,将缺少的模块添加到.spec"文件中的hiddenimport=[]"处,如下所示:

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"]

然后使用此文件生成您的 exe 文件:

Then use this file to generate your exe file:

pyinstaller my.spec

这篇关于使用pyinstaller打包python程序,出现“NoModuleFindError";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆