Question

I created an executable .exe from a .py file using the latest version of cx_freeze for Python 2.7 with the following setup.py file:

import sys
from cx_Freeze import setup, Executable

setup(
    name = "Any",
    version = "1.0",
    description = "Any",
    executables = [Executable("D:\\script.pyw", base = "Win32GUI")])

I ran it from command line:

python setup.py build

Then I got the executable file in the build directory as expected. It ran perfectly.

Now, If I move the executable file into a different directory on the same computer. I get the following error dialog:

enter image description here

My guess is that I need to embed something into the executable file to make it work not only on my computer but on any other computer where Python is not installed by changing something in the setup.py file. What could be it missing?

Was it helpful?

Solution

I am building compiled executable as follows.

Using following versions:

OS: Windows-7-6.1.7601-SP1
Python: 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)]
cx_Freeze: 4.2.3

I have this code hello_tkinter.py:

from Tkinter import *
import ttk

class Main(Tk):
    def __init__(self, *args, **kwargs):
        Tk.__init__(self, *args, **kwargs)

        self.frame = ttk.Frame(self)
        self.frame.pack(expand=True, fill=BOTH, padx=5, pady=5)

        self.button = ttk.Button(self.frame, text="Test")
        self.button.pack(expand=True, fill=BOTH)

root = Main()
root.mainloop()

I call this script installed with cx_freeze:

c:\Python27\Scripts\cxfreeze.bat hello_tkinter.py --target-dir=Bin/tkinter --base-name=Win32GUI --target-name=hello_tkinter.exe

And I get the directory containing:

tcl\
tk\
_ctypes.pyd
_tkinter.pyd
bz2.pyd
hello_tkinter.exe
MSVCR90.dll
python27.dll
tcl85.dll
tk85.dll
unicodedata.pyd

It works fine and even if I move the directory. You did take the whole directory, not just the exe, did not you? The executable was also tested on Windows XP without Python installed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top