4

I'm trying to convert a basic tkinter GUI program to an .exe using py2exe. However I've run into an error using the following conversion script.

# C:\Python26\test_hello_con.py py2exe

from distutils.core import setup
import py2exe

setup(windows=[r'C:\Python26\py2exe_test_tk.py'])

C:\Python26\py2exe_test_tk.py is the following code

import Tkinter as tk

root = tk.Tk()
root.title("Test")


label1 = tk.Label(root,text="Hello!",font=('arial', 10, 'bold'), bg='lightblue')
label1.pack(ipadx=100, ipady=100)


root.mainloop()

This is the error I get when I try to run the newly created .exe

Traceback (most recent call last):
  File "py2exe_test_tk.py", line 4, in <module>
  File "Tkinter.pyc", line 1643, in __init__
_tkinter.TclError: Can't find a usable init.tcl in the following directories: 
    {C:/Users/My_Name/lib/tcl8.5} {C:/Users/My_Name/lib/tcl8.5} C:/Users/lib/tcl8.5 {C:/Users/My_Name/library} C:/Users/library C:/Users/tcl8.5.8/library C:/tcl8.5.8/library



This probably means that Tcl wasn't installed properly.

I'm pretty sure it's something in my conversion script thats giving me problems. What did I omit? Or does someone have an example of what the conversion script would look like for a tkinter GUI program? Also is it possible to divert the output .exe files to my desktop?

EDIT:

The error report said that I was missing init.tcl from {C:/Users/My_name/lib/tcl8.5}. So i made that directory and put a copy of init.tcl there. Now when I try to run the .exe it states that MSVCR90.dll is missing from my computer and is needed to run my program.

Also this is python 2.6.5 on Windows 7.

knitti
  • 6,817
  • 31
  • 42
rectangletangle
  • 50,393
  • 94
  • 205
  • 275
  • 2
    I was experiencing similar issues with both py2exe for Python 2.6.4 and cx_Freeze for Python 3.1.2 on Win7 64-bit. I found that the tcl subdirectories(tcl8.5 and tk8.5) were not being included in the generated dist directory. I copied the two directories from my Python26\tcl to dist\tcl8.6 and dist\tk8.5 respectively and the py2exe generated binary stopped complaining about missing tcl.I eventually reinstalled the py2exe and the problem disappeared. Now after the resinstallation of py2exe the tcl directories now reside under dist\tcl\tcl8.5 and dist\tcl\tk8.5. – T.P. Oct 19 '10 at 05:33

4 Answers4

2

For your original problem I can't say what exactly the problem is, but usually it helps with trial-and-error to guess missing files and directories. If you know what you're missing, add them to your packages (for python modules) or data_files (for other files).

The second problem is the result of some c-modules (and python itself) being build with MS Visual Studio, thus having a dependency to the MS Visual C++ 9.0 (2008) runtime. You can solve this by either:

  • owning a copy of Visual Studio (Express Edition doesn't count), so that you are permitted to redistribute the MSVCR dependencies (under the condition that you forbid your users reengeneering etc. of the dependend parts)

  • pointing your users to the download of the MS Visual C++ 2008 Redistributable package at Microsoft.

knitti
  • 6,817
  • 31
  • 42
1

I found a bug on the virutalenv site which suggested the following https://github.com/pypa/virtualenv/issues/93

for windows in your directory "C:\Environments\VirtualEnv\Scripts\activate.bat" just add which are set to the right path to TCL and TK for your python version

set "TCL_LIBRARY=C:\Python27\tcl\tcl8.5"
set "TK_LIBRARY=C:\Python27\tcl\tk8.5"

and restart your cmd or shell

It worked very well for me when I had this error.

JamesD
  • 2,466
  • 24
  • 40
0

py2exe doesn't work with modules, i've heard of one called c_freeze which apparently works with modules, try that? http://cx-freeze.sourceforge.net/

Infamouslyuseless
  • 922
  • 2
  • 8
  • 15
0

With respect to MSVCR90.dll, see this post which packages it and maybe less preferable than having user install it separately.

Also, the specific issue in that post was mine and i still don't understand root cause. That said, a complete uninstall python and clean rebuild worked great... maybe that is your issue too. py2exe gives RuntimeError: Too early to create image

Community
  • 1
  • 1
charo
  • 715
  • 1
  • 7
  • 14