Python || How To Create An Executable Using Cx_Freeze

Print Friendly, PDF & Email

Python is a simple and powerful programming language for scripting and application development. Various GUI packages available for Python makes it a great choice for developing applications. But what if you want to create an executable file from the python script you just created? This page demonstrates that process using a free third party module called “cx_Freeze.” This module is ideal for use because it supports Python 2.3 or higher.


cx_Freeze is a set of scripts and modules for freezing Python scripts into executables, in much the same way that py2exe and py2app do. Unlike these two tools, cx_Freeze is cross platform and should work on any platform that Python itself works on. It supports Python 2.3 or higher (including Python 3), since it makes use of the zip import facility which was introduced in 2.3.

Note: Binary packages must be compatible with the Python installation on your system or you will get errors in your frozen executables about missing builtin modules or missing symbols. This is not likely to be a problem on Windows (since most installations are from but on Linux it is more likely (since Linux distributions often package Python in different ways). If you get such errors, download the source package and build the binaries yourself.


First, download the cx_Freeze installer which corresponds to the python version that is installed on your system. I have Python 3.2 installed on my Windows computer, so I will select the cx_Freeze version 3.2 installer to download.

Next, follow the command prompts from the installer and wait!

When the cx_Freeze installer is completed, you should see the newly installed files which correspond to this module located in the following directory:


If everything installed correctly, you should now be ready to create executable Python programs!


To use cx_Freeze you need to create a file which tells the cx_Freeze “compiler” what you want to do. Here’s a sample file whose simplicity is appropriate for our sample “Hello World” program.

This is the sample Python file.

This is the setup file.


After you have created the file and inserted the data that corresponds to your specific python script within the setup file, copy and paste the file and ALL of the python files associated with your current python program into the following directory:


Here is a sample screenshot demonstrating the above instructions: (click to enlarge)

In order to start compiling the file, we need to open the command prompt (CMD). Click here if you dont know how to do this.

Next, copy and paste these commands into the command prompt (CMD).

#1. Change directories into the python folder

cd C:\Python32

#2. Start compiling the program using the file

python.exe build

If cx_Freeze finished with no errors, then the process should be complete!

The python executable should be located in the following directory:


Here is a sample screenshot demonstrating the directory where the executable file resides: (click to enlarge)

** NOTE: In order for the executable file to run, the other files within that folder that was generated by cx_Freeze must be bundled with the executable file at all times.

And there you have it! Here is a sample screenshot of the running executable: (click to enlarge)

17 Responses to Python || How To Create An Executable Using Cx_Freeze

  1. Avatar pywriter says:

    thank you,sir
    i searched all over the web but could not get a reliable answer.again thank you very very much.

  2. Avatar kaniska says:

    You are great……

  3. Avatar VIRkid says:

    THANK you sir Learned alot

  4. Avatar vimal says:


  5. Avatar Maxxie says:

    hello sir, i created the exe file and it works fine….but if i try to run the exe by copying it in a folder in the same path an error pops up saying cannot get zipimporter instance…can u assist me how to get rid of it.

    • admin admin says:


      When you move the executable file, make sure you also move all of the files that was generated by cx_freeze too, or else the executable file will not run.

      In your case, the executable was looking for the file “” but could not find it, thus you got the error message stating “cannot get zipimporter instance”

      In order for the executable to run, the files generated by cx_freeze must be placed in the same directory as the executable file at all times.

      Refer to screenshot #2 on this page for reference.

      • Avatar Maxxie says:

        thnku sir,
        in some other sites it was suggested to disable DEP(Data execution prevention) from system properties…does that work to remove this error…
        one more thing , will the exe file work on a system which does not have python install cause i need to send it to different people(i have used cx_freeze )

        • admin admin says:

          Hello again,

          To answer your questions

          (1) Unfortunately I dont know of any fix associated with disabling the DEP so I cannot help you there, but my previous reply should probably fix your issue

          (2) Assuming you are using cx_freeze with Windows, If the people you send the exe to also has Windows computers, then no they do not need to have Python installed to run your program

          Thanks for visiting!

  6. Avatar Justik says:

    Thank you, Helps a lot.

  7. Avatar Tanjid says:

    Hello sir,
    I might be making some mistakes but whenever I run my exe file, it closes right away. Is there anything that I’m doing wrong?


    • admin admin says:


      Is your exe a console program, or does it have a GUI?

      If its a console program, you probably need to place an input statement in the code before the program ends, that way the program will halt unless you press enter.

      Look at the example hello world file listed on this page for ideas!

  8. Avatar cobus says:

    thank you so muck

  9. Avatar sundeep says:

    hello sir,
    i used cx_freeze on windows and made an app using python. will i able to run the same .exe file on linux based OS?

  10. great help after a lot of struggle. thanks a lot

  11. Avatar presea nagoya says:


    I received the followwing error:

    TypeError: __init__() got an unexpected keyword argumente ‘copyDependentFiles’

    Could you please tell mme the possible solutions,


Leave a Reply