BitsBitsBits
BitsBitsBits

Reputation: 604

cx_Freeze with python packages (not just one module)

All of the cx_Freeze examples are for one file (module). I need to make an executable for an entire python package. Why is that hard to make?

Here's my directory:

test1/
  __init__ 
  __main__

The way I run this from the command line is by using the following cmd

python -m test1 

__init__ is empty and __main__ just have a simple print statement. I am using python 3.5.1 but I can switch to python 3.4 if that would fix the problem

Here is my setup.py for win64

from cx_Freeze import setup, Executable
import sys

build_exe_options = {"packages": ['test1'],
                     "include_files": []
                    }
executables = [
                Executable("__main__")
              ]
setup(
    name = "Foo",
    version = "0.1",
    description = "Help please!",
    author = "me",
    options = {"build_exe": build_exe_options},
    executables = executables
)

Update: 1- see the comment below for solution for this approach 2- switch to pyinstaller because it can produce one exe file not a folder

Upvotes: 0

Views: 1518

Answers (2)

Petre Iordanescu
Petre Iordanescu

Reputation: 1

That seems to be the solution. Also be aware thatcxFreze will not build "one file" executable as pyInstaller does, but put along with executable created file a series of DLL that mainly run Python If this is still not good, you can build a MSI package as Windows installer. This will build a msi package, default in a dist/ directory. To do that, run cxfreeze using the build_msi instead of simple build.

Upvotes: 0

MrLeeh
MrLeeh

Reputation: 5589

Freezing a whole package doesn' t make sense because to create an executable binary you will want a Python script that can be run standalone from the command line. A package normally isn't started out-of-the-box but would get imported by another module.

However you can always import a package in your script so when you freeze it the package gets included in your distribution.

So do something like this:

test1/
  __init__ 
  __main__
run_test.py

run_test.py now imports test1 and starts your function that does whatever you want.

import test1
run_the_whole_thing()

Note: You will need to change your Executable in the setup.py to run_test.py.

Upvotes: 1

Related Questions