3

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.

John Crow
  • 927
  • 3
  • 13
  • 26
  • Possible duplicate of [pyinstaller, spec file, ImportError: No module named 'blah'](http://stackoverflow.com/questions/7436132/pyinstaller-spec-file-importerror-no-module-named-blah) – user1251007 Jan 26 '17 at 10:14

1 Answers1

10

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.

Community
  • 1
  • 1
fhdrsdg
  • 10,297
  • 2
  • 41
  • 62
  • 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. – rafaelvalle May 24 '16 at 16:39
  • 1
    @rafaelvalle This may also be achieved by adding `hiddenimports=['FileDialog',],` in th .spec file's `Analysis()` section. – Ber Feb 20 '17 at 11:19