How do I use cx_freeze? How do I use cx_freeze? python python

How do I use cx_freeze?


  • Add import sys as the new topline
  • You misspelled "executables" on the last line.
  • Remove script = on last line.

The code should now look like:

import sysfrom cx_Freeze import setup, Executablesetup(    name = "On Dijkstra's Algorithm",    version = "3.1",    description = "A Dijkstra's Algorithm help tool.",    executables = [Executable("Main.py", base = "Win32GUI")])

Use the command prompt (cmd) to run python setup.py build. (Run this command from the folder containing setup.py.) Notice the build parameter we added at the end of the script call.


I'm really not sure what you're doing to get that error, it looks like you're trying to run cx_Freeze on its own, without arguments. So here is a short step-by-step guide on how to do it in windows (Your screenshot looks rather like the windows command line, so I'm assuming that's your platform)

  1. Write your setup.py file. Your script above looks correct so it should work, assuming that your script exists.

  2. Open the command line (Start -> Run -> "cmd")

  3. Go to the location of your setup.py file and run python setup.py build

Notes:

  1. There may be a problem with the name of your script. "Main.py" contains upper case letters, which might cause confusion since windows' file names are not case sensitive, but python is. My approach is to always use lower case for scripts to avoid any conflicts.

  2. Make sure that python is on your PATH (read http://docs.python.org/using/windows.html)1

  3. Make sure are are looking at the new cx_Freeze documentation. Google often seems to bring up the old docs.


I ran into a similar issue. I solved it by setting the Executable options in a variable and then simply calling the variable. Below is a sample setup.py that I use:

from cx_Freeze import setup, Executableimport sysproductName = "ProductName"if 'bdist_msi' in sys.argv:    sys.argv += ['--initial-target-dir', 'C:\InstallDir\\' + productName]    sys.argv += ['--install-script', 'install.py']exe = Executable(      script="main.py",      base="Win32GUI",      targetName="Product.exe"     )setup(      name="Product.exe",      version="1.0",      author="Me",      description="Copyright 2012",      executables=[exe],      scripts=[               'install.py'               ]      )