ImportError: No module named FileDialog - after PyInstaller

13,517

According to this question adding import FileDialog solves the problem. Matplotlib seems to need this.
However, I've used Pyinstaller on a script of mine also importing matplotlib and it gives no such error. So I don't know what exacly is the problem here.

Share:
13,517

Related videos on Youtube

John Crow
Author by

John Crow

Updated on June 04, 2022

Comments

  • John Crow
    John Crow almost 2 years

    I have written a program that I have tried to turn into an executable using PyInstaller. Pyinstaller appears to have finished without any errors and I end up with an application in /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?

    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.

  • rafaelvalle
    rafaelvalle almost 8 years
    fhdrsdg, In your script, did you use FileDialog or tkFileDialog? If you have not, this might have been the reason why you had no such error.
  • Ber
    Ber about 7 years
    @rafaelvalle This may also be achieved by adding hiddenimports=['FileDialog',], in th .spec file's Analysis() section.