Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use cx_freeze?

I've created my setup.py file as instructed but I don't actually.. understand what to do next. Typing "python setup.py build" into the command line just gets a syntax error.

So, what do I do?

setup.py:

from cx_Freeze import setup, Executable  setup(     name = "On Dijkstra's Algorithm",     version = "3.1",     description = "A Dijkstra's Algorithm help tool.",     exectuables = [Executable(script = "Main.py", base = "Win32GUI")]) 
like image 970
Edwin Avatar asked Mar 27 '12 18:03

Edwin


People also ask

What is cx_Freeze?

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.7 or higher (including Python 3).

What is cx_Freeze Python error in main script?

According to some Windows users' reports, the problem “cx_Freeze: Python error in main script” may be caused by a poorly written Phyton application like PlayTV or Raptr. If you are in this case, you can try to uninstall PlayTV or Raptr to fix the cx_Freeze Python error. There are two ways to uninstall applications.


2 Answers

  • 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 sys from cx_Freeze import setup, Executable  setup(     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.

like image 188
Bryan Avatar answered Sep 20 '22 01:09

Bryan


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.

like image 21
aquavitae Avatar answered Sep 21 '22 01:09

aquavitae