简体   繁体   English

使用pyinstaller打包python程序出现“NoModuleFindError”

[英]Using pyinstaller to package python program and there is a “NoModuleFindError”

I use pyinstaller to package my python program into executable program(exe).我使用 pyinstaller 将我的 python 程序打包成可执行程序(exe)。

my program version:我的程序版本:

Pyinstaller :3.3.1 pyinstaller:3.3.1

Python :3.6.1 Windows:10-10.0.16299-SP0 Python:3.6.1 视窗: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.我可以在命令行窗口中使用命令“python data_processing_gui.py”运行 data_processing_gui.py 文件而没有任何错误。


I use the command to package my python program(which name is data_processing_gui.py):我使用命令打包我的python程序(名称为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:当我在windows的命令行窗口中运行上面的代码时没有错误,但是当我运行目标程序(data_progressing_gui.exe)时,有一个ModuleNotFindError ,错误信息是:

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回溯(最近一次调用):文件“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", 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文件“c:\\users\\fanyu\\anaconda3\\lib\\site-packages\\PyInstaller\\loader\\pyimod03_importers.py”,第 631 行,在 exec_module exec(bytecode, module. dict ) 文件“site-packages\\pywt__init__.py”中,第 17 行,在文件“c:\\users\\fanyu\\anaconda3\\lib\\site-packages\\PyInstaller\\loader\\pyimod03_importers.py”中,第 631 行,在 exec_module exec(bytecode, module. dict ) 文件“site-packages\\pywt_functions .py”,第 17 行,在文件“c:\\users\\fanyu\\anaconda3\\lib\\site-packages\\PyInstaller\\loader\\pyimod03_importers.py”,第 714 行,在 load_module 模块 = loader.load_module(fullname) 文件“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

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.好像程序找不到指定的包路径(pywt._extensions._cwt),但是,我已经在pyinstaller的参数列表中添加了路径。

At first,I think maybe there is something wrong with my pyinstaller,so I've tried to reinstall it.起初,我想可能是我的 pyinstaller 有问题,所以我尝试重新安装它。 Then I write a simple python program to test it,it runs correctly.然后我写了一个简单的python程序来测试它,它运行正常。

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.我已经尝试了很多但无法解决它,所以我在这里寻求帮助,如果有人可以提供任何建议,我将不胜感激。

I find a solution for my problem in the answers to the following question ModuleNotFoundError: No module named 'pandas._libs.tslibs.timedeltas'我在以下问题的答案中找到了解决我的问题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:解决方法是:使用pyinstaller生成“.spec”文件后,将缺少的模块添加到“.spec”文件中的“hiddenimport=[]”处,如下所示:

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

Then use this file to generate your exe file:然后使用此文件生成您的 exe 文件:

pyinstaller my.spec

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

相关问题 如何在python中使用pyinstaller插入或包含包? - How to insert or include package using pyinstaller in python? Python 使用 pyinstaller 创建可安装程序 - Python Creating an installable program using pyinstaller 无法打包使用pyinstaller导入了带有matplotlib的python脚本 - Unable to package a python script which with matplotlib imported using pyinstaller 如何使用 pyinstaller 安装 package 多文件夹 python 应用程序 - How to package multi folder python apps using pyinstaller 使用 PyInstaller 将带有命令行参数的 Python 程序转换为可执行文件 - Converting Python program with command line argument into executable using PyInstaller 如何在不使用pyinstaller的情况下为带有spacy的python程序创建exe文件? - How to create a exe file for python program with spacy without using pyinstaller? Python 程序可在终端中运行,但在使用 PyInstaller 生成 EXE 时无法运行 - Python Program Working In Terminal But Not When Made Into EXE Using PyInstaller 使用 PyInstaller 编译 python,使用 Python - Compile python using PyInstaller, with Python 由于 package 未找到错误,无法使用 pyinstaller 将 python 脚本转换为 exe - Cannot convert python script to exe using pyinstaller due to package not found error 无法使用 PyInstaller 库从 .py 到 .exe 构建 python 程序 - can't build python program from .py to .exe using PyInstaller library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM