8

My question is much the same as this already answered question(Missing tkinter attributes after converting to py2exe executable). But it relates to python 2.7, which uses Tkinter, instead of tkinter.

I am basically having the same issue running my executable after compiling.

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 as I am using Tkinter with python 2.7 it means I can not do:

from tkinter import FileDialog

I have tried using

from tkFileDialog import askopenfilename

and

import tkFileDialog

but none have worked. Am I facing having to upgrade python to 3 just to be able to properly compile Tkinter? Or is there a workaround I'm 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 have tried to specify tkFileDialog in options: includes: but still no luck :(

options={'py2exe': {'includes': ['Tkinter', 'tkFileDialog']}, }

UPDATE:

I found the answer after some investigating. You can actually just

import FileDialog

UPDATE2:

If you want to avoid the "unused import" feedback some debuggers and ide's give you, you can add the package FileDialog to the packages dictionary of py2exe in stead

options={'py2exe': {'packages': ['FileDialog']},}

Perhaps someone can help clarify why either is more appropriate?

1
  • Update 2 worked very well for me. Thank you. Commented Oct 28, 2016 at 15:12

1 Answer 1

3

Instead of using "includes" use "packages" and only specify the package, in this case 'Tkinter'.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your reply! Unfortunately your answer does not seem to work for me. I get the same importerror
I believe the problem is that FileDialog was/is a seperate package from Tkinter, I have just tested your solution using FileDialog instead of Tkinter in packages, and was able to compile. I will update the question, and I thank you for pointing me in the right direction :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.