Py2exe with Tkinter

I am trying to convert the tkinter GUI base program to .exe using py2exe. However, I encountered 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 a newly created .exe file

 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 am sure this is something in my conversion script that gives me problems. What did I miss? Or does someone have an example of what the conversion of the script for the tkinter GUI program will look like? Also, is it possible to redirect the output .exe files to the desktop?

EDIT:

The error report indicates that I am missing init.tcl from {C: /Users/My_name/lib/tcl8.5} . So I created this directory and placed a copy of init.tcl there . Now, when I try to run .exe, it indicates that MSVCR90.dll is missing on my computer and is needed to run my program.

Also this is python 2.6.5 on Windows 7.

+4
source share
4 answers

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

The second problem is that some c-modules (and python itself) are built using MS Visual Studio, thereby having a dependency on the MS Visual C ++ 9.0 (2008) runtime. You can solve this problem:

  • owning a copy of Visual Studio (Express Edition is not taken into account), so you are allowed to redistribute MSVCR dependencies (provided that you prohibit users from reengineering, etc. of dependent parts)

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

+2
source

I found an error on the virutalenv website which suggested the following https://github.com/pypa/virtualenv/issues/93

for windows in your directory "C: \ Environments \ VirtualEnv \ Scripts \ activate.bat" just add that are configured to the correct 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 reload cmd or shell

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

+1
source

py2exe does not work with modules, I heard about one named c_freeze, which, apparently, works with modules, try it? http://cx-freeze.sourceforge.net/

0
source

Regarding MSVCR90.dll , see this post, which packs it and may be less preferred than installing the user separately.

In addition, the specific problem in this message was mine, and I still do not understand the root cause. However, a full remote python and a clean rebuild worked just fine ... maybe this is your problem too. py2exe gives RuntimeError: creating image too early

0
source

All Articles