My question is almost the same as this already answered question ( Lack of tkinter attributes after conversion to py2exe executable ). But it refers to python 2.7, which uses Tkinter instead of tkinter.
I basically have the same problem as the executable after compilation.
Traceback (most recent call last): File "main.py", line 5, in <module> File "gui.pyc", line 5, in <module> File "matplotlib\backends\backend_tkagg.pyc", line 7, in <module> File "six.pyc", line 199, in load_module File "six.pyc", line 113, in _resolve File "six.pyc", line 80, in _import_module ImportError: No module named FileDialog
But since I am using Tkinter with python 2.7, this means that I cannot:
from tkinter import FileDialog
I tried using
from tkFileDialog import askopenfilename
and
import tkFileDialog
but no one worked. Am I faced with the need to upgrade python to 3 in order to be able to compile Tkinter correctly? Or is there a workaround that I am missing?
This is my current setup.py
from distutils.core import setup from glob import glob import py2exe import sys import matplotlib sys.path.append("C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\redist\\x86\\Microsoft.VC90.CRT") data_files = [("Microsoft.VC90.CRT", glob(r'C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\redist\x86\Microsoft.VC90.CRT\*.*'))] data_files.extend(matplotlib.get_py2exe_datafiles()) setup( data_files=data_files, windows=['main.py'], packages=[''], name='ZLA', version='0.1 beta', description='Troubleshooter.', requires=['matplotlib', 'PIL', 'py2exe'] )
I tried to specify tkFileDialog in the parameters: includes: but still no luck :(
options={'py2exe': {'includes': ['Tkinter', 'tkFileDialog']}, }
UPDATE:
I found the answer after some investigation. You really can just
import FileDialog
UPDATE2:
If you want to avoid feedback from "unused import", some debuggers give you an idea, you can add the FileDialog package to the py2exe package dictionary instead
options={'py2exe': {'packages': ['FileDialog']},}
Perhaps someone can help clarify why this is more appropriate.