0

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?

1 Answer 1

1

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.

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

2 Comments

I just took the executable in my case and it didn't work. should it not? If not then can it create just one single executable? What will be it's average size?
No, it should not. There are dynamic libraries linked etc. Single executable is neither possible in cx_freeze, nor recommended packaging for Python. In Python 2.7 py2exe and pyinstaller can do it. Anyway, all libraries which can do it use hacks to achieve it and antivirus programs may be very suspicious of the way how your exe will unpack when you run it. Your one-exe-packs-all may load very slow for that reason on some systems. I always encourage packing cx_freeze output directory using Inno setup to create Windows installer.

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.