简体   繁体   English

ImportError:没有名为FileDialog的模块 - 在PyInstaller之后

[英]ImportError: No module named FileDialog - after PyInstaller

I have written a program that I have tried to turn into an executable using PyInstaller. 我编写了一个程序,我试图使用PyInstaller变成可执行文件。 Pyinstaller appears to have finished without any errors and I end up with an application in /dist/my_program. Pyinstaller似乎已经完成没有任何错误,我最终得到了/ dist / my_program中的应用程序。 However, when I try to run that application a console window flashes up for a second with a traceback: 但是,当我尝试运行该应用程序时,控制台窗口会闪回一秒钟并带有回溯:

Edit: I have copied the traceback out. 编辑:我已经复制了追溯。 There may be a mistake as I had to type it up from a screenshot because it only flashes up. 可能有一个错误,因为我必须从屏幕截图中输入它,因为它只会闪烁。

Traceback (most recent call last):
File "<string>", line 14, in <module>
File "C:\Users\user\desktop\PyInstaller-2.1\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\matplotlib.pyplot", line 108, in <module>
File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\matplotlib.backends", line 32, in pylab_setup
File "C:\Users\user\desktop\PyInstaller-2.1\PyInstaller\loader\pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\matplotlib.backends.backend_tkagg", line 7, in <module>
File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\six", line 194, in load_module
File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\six", line 108, in _resolve
File "C:\Users\user\desktop\PyInstaller-2.1\my_program\build\my_program\out00-PYZ.pyz\six", line 779, in _import_module
ImportError: No module named FileDialog

Below are the imports that I have in my code: 以下是我的代码中的导入:

import Tkinter
from tkFileDialog import askopenfilename
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import subprocess
from PIL import Image, ImageTk
import os

Does anyone know whats causing this/what the fix is? 有谁知道导致这个/什么修复是什么? I presume the error is the importation of tkFileDialog? 我认为错误是tkFileDialog的输入?

Edit2: the program runs fine when I run it in my interpreter (Spyder) but when I packaged it using PyInstaller the resulting application gives this error. Edit2:当我在我的解释器(Spyder)中运行它时,程序运行正常但是当我使用PyInstaller打包它时,生成的应用程序会出现此错误。

According to this question adding import FileDialog solves the problem. 根据这个问题,添加import FileDialog解决了这个问题。 Matplotlib seems to need this. Matplotlib似乎需要这个。
However, I've used Pyinstaller on a script of mine also importing matplotlib and it gives no such error. 但是,我在我的脚本上使用了Pyinstaller,也导入了matplotlib,它没有给出这样的错误。 So I don't know what exacly is the problem here. 所以我不知道这里的问题究竟是什么。

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

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