Im having troubles learning how to make an executable so can someone show me what Im doing wrong
[import time
from cx_Freeze import setup, Executable

setup(
name = "hello",
version = "0.1",
description = "the typical 'Hello, world!' script",
executables = [Executable("hello.py")])

[GO AHEAD AND IGNORE THE REST OF THE CODE I DONT THINK IT MATTERS]
print('Hello World!!!!')
time.sleep(1)
print ('what is your name?')
name = input()
a = ('Hello ')
b = (' my name is com')
string = a+name +b
print (string)
time.sleep(2)
print('What is your favorite color?')
color = input()
c= ('Thats awesome ')
print(c+name)
time.sleep(2)
d=(' is my favorite color too')
print(color+d)
time.sleep(2.7)
e =('bye ')
print(e+name)]

Recommended Answers

All 21 Replies

Assuming you have a script called hello.py which you want to turn into an executable, this can be accomplished by this command:

cxfreeze hello.py --target-dir dist

Source

You must run the cx_freeze script to modify your script, you don't include or import cx_freeze on your scripts.

The info you misunderstood, is to make distutils setup scripts with cx_freeze.

Maybe this shows you how to package a console program ...

"""
con_setup.exe

Using cx_freeze with Python31 to package a console
program to an executable file (.exe in Windows OS).

Might want to put a console-wait-line in at the end of your program.

Put this setup program and your console program file into the same 
directory.  Change the filename in this setup program and also edit 
name, version and description in setup() if you so desire.

Run the build process by running the command: 
python con_setup.py build

A directory 'build' is created with a subdirectory 'exe.win32-3.1'
containing all the files needed for distribution including the 
.exe file named after the console program file.

The total distribution has a size of about 4.2 Mb.
"""

from cx_Freeze import setup, Executable

# change the filename to your program file
filename = "99BottlesOfBeer3.py"

setup(
    name = "99Bottles",
    version = "1.0",
    description = "console cx_Freeze script",
    executables = [Executable(filename)])

im so confused so I run the cx_freexe script in a seprate module

For your example you open python command-line and type.

cxfreeze hello.py --target-dir dist

as it is on the documentation, your hello.py its a normal python script, without no imports or references to cx_freeze.

Testet this out with python 2.65
This should work for python 3.xx to.
Made a dir E:\1py\frezze
In that dir i have 2 files.

#cx_freeze test save in dir E:\1py\freeze
#date.py
import time

date_old = "05.26.1999"

#Use strptime(time_str, format_str) to form a time tuple
time_tuple = time.strptime(date_old, "%m.%d.%Y")

#Use time.strftime(format_str, time_tuple) to create new format
date_new = time.strftime("%b-%d", time_tuple)

print(date_old)  # 14-05-1999
print(date_new)  # May-14
raw_input('press enter to exit!')
#Cx_freeze test save in dir E:\1py\freeze
#my_cx_freeze.py
"""
con_setup.exe

Using cx_freeze with Python31 to package a console
program to an executable file (.exe in Windows OS).

Might want to put a console-wait-line in at the end of your program.

Put this setup program and your console program file into the same 
directory.  Change the filename in this setup program and also edit 
name, version and description in setup() if you so desire.

Run the build process by running the command: 
python con_setup.py build

A directory 'build' is created with a subdirectory 'exe.win32-3.1'
containing all the files needed for distribution including the 
.exe file named after the console program file.

The total distribution has a size of about 4.2 Mb.
"""

from cx_Freeze import setup, Executable

# change the filename to your program file
filename = "date.py"

setup(
    name = "date",
    version = "1.0",
    description = "console cx_Freeze script",
    executables = [Executable(filename)])

So then i have 2 files in E:\1py\freeze(date.py and my_cx_freeze.py)

#From cmd
c:\e:
E:\cd 1py
E:\1py\cd freeze
E:\1py\freeze>python my_cx_freeze.py build  #This is the line that start build process
running build
running build_exe
creating directory build\exe.win32-2.6
copying c:\python26\lib\site-packages\cx_Freeze\bases\Console.exe -> build\exe.win32-2.6\date.exe
copying C:\WINDOWS\system32\python26.dll -> build\exe.win32-2.6\python26.dll
writing zip file build\exe.win32-2.6\library.zip

  Name                      File
  ----                      ----
m BUILD_CONSTANTS
m StringIO
m UserDict
m __builtin__
m __future__
m __main__
m _abcoll
m _bisect
m _codecs
m _codecs_cn
m _codecs_hk
m _codecs_iso2022
m _codecs_jp
m _codecs_kr
m _codecs_tw
m _collections
m _functools
m _heapq
m _locale
m _multibytecodec
m _random
m _sre
m _strptime
m _struct
m _subprocess
m _threading_local
m _warnings
m abc
m array
m base64
m bdb
m binascii
m bisect
m bz2                       c:\python26\DLLs\bz2.pyd
m cPickle
m cStringIO
m calendar
m cmd
m codecs
m collections
m copy
m copy_reg
m cx_Freeze__init__         c:\python26\lib\site-packages\cx_Freeze\initscripts\Console.py
m date__main__              date.py
m datetime
m difflib
m dis
m doctest
m dummy_thread
P encodings
m encodings.aliases
m encodings.ascii
m encodings.base64_codec
m encodings.big5
m encodings.big5hkscs
m encodings.bz2_codec
m encodings.charmap
m encodings.cp037
m encodings.cp1006
m encodings.cp1026
m encodings.cp1140
m encodings.cp1250
m encodings.cp1251
m encodings.cp1252
m encodings.cp1253
m encodings.cp1254
m encodings.cp1255
m encodings.cp1256
m encodings.cp1257
m encodings.cp1258
m encodings.cp424
m encodings.cp437
m encodings.cp500
m encodings.cp737
m encodings.cp775
m encodings.cp850
m encodings.cp852
m encodings.cp855
m encodings.cp856
m encodings.cp857
m encodings.cp860
m encodings.cp861
m encodings.cp862
m encodings.cp863
m encodings.cp864
m encodings.cp865
m encodings.cp866
m encodings.cp869
m encodings.cp874
m encodings.cp875
m encodings.cp932
m encodings.cp949
m encodings.cp950
m encodings.euc_jis_2004
m encodings.euc_jisx0213
m encodings.euc_jp
m encodings.euc_kr
m encodings.gb18030
m encodings.gb2312
m encodings.gbk
m encodings.hex_codec
m encodings.hp_roman8
m encodings.hz
m encodings.idna
m encodings.iso2022_jp
m encodings.iso2022_jp_1
m encodings.iso2022_jp_2
m encodings.iso2022_jp_2004
m encodings.iso2022_jp_3
m encodings.iso2022_jp_ext
m encodings.iso2022_kr
m encodings.iso8859_1
m encodings.iso8859_10
m encodings.iso8859_11
m encodings.iso8859_13
m encodings.iso8859_14
m encodings.iso8859_15
m encodings.iso8859_16
m encodings.iso8859_2
m encodings.iso8859_3
m encodings.iso8859_4
m encodings.iso8859_5
m encodings.iso8859_6
m encodings.iso8859_7
m encodings.iso8859_8
m encodings.iso8859_9
m encodings.johab
m encodings.koi8_r
m encodings.koi8_u
m encodings.latin_1
m encodings.mac_arabic
m encodings.mac_centeuro
m encodings.mac_croatian
m encodings.mac_cyrillic
m encodings.mac_farsi
m encodings.mac_greek
m encodings.mac_iceland
m encodings.mac_latin2
m encodings.mac_roman
m encodings.mac_romanian
m encodings.mac_turkish
m encodings.mbcs
m encodings.palmos
m encodings.ptcp154
m encodings.punycode
m encodings.quopri_codec
m encodings.raw_unicode_escape
m encodings.rot_13
m encodings.shift_jis
m encodings.shift_jis_2004
m encodings.shift_jisx0213
m encodings.string_escape
m encodings.tis_620
m encodings.undefined
m encodings.unicode_escape
m encodings.unicode_internal
m encodings.utf_16
m encodings.utf_16_be
m encodings.utf_16_le
m encodings.utf_32
m encodings.utf_32_be
m encodings.utf_32_le
m encodings.utf_7
m encodings.utf_8
m encodings.utf_8_sig
m encodings.uu_codec
m encodings.zlib_codec
m errno
m functools
m gc
m genericpath
m getopt
m gettext
m heapq
m imp
m inspect
m itertools
m keyword
m linecache
m locale
m marshal
m math
m msvcrt
m nt
m ntpath
m opcode
m operator
m optparse
m os
m pdb
m pickle
m posixpath
m pprint
m quopri
m random
m re
m repr
m select                    c:\python26\DLLs\select.pyd
m shlex
m signal
m sre_compile
m sre_constants
m sre_parse
m stat
m string
m stringprep
m strop
m struct
m subprocess
m sys
m tempfile
m textwrap
m thread
m threading
m time
m token
m tokenize
m traceback
m types
m unicodedata               c:\python26\DLLs\unicodedata.pyd
m unittest
m warnings
m zipimport
m zlib

copying c:\python26\DLLs\bz2.pyd -> build\exe.win32-2.6\bz2.pyd
copying c:\python26\DLLs\select.pyd -> build\exe.win32-2.6\select.pyd
copying c:\python26\DLLs\unicodedata.pyd -> build\exe.win32-2.6\unicodedata.pyd

Now i have a build dir in E:\1py\freeze\build(date.exe file)
Testet date.exe and it work

This 3 file is needed.
Delete rest as a test.
---
date.exe
library.zip
python26.dll
---
Size 3.40mb

For your example you open python command-line and type.

cxfreeze hello.py --target-dir dist

as it is on the documentation, your hello.py its a normal python script, without no imports or references to cx_freeze.

do I have to save it in a certain spot because It's just keeps telling me invalid syntax

do I have to save it in a certain spot because It's just keeps telling me invalid syntax

Have you look at my post it should be clear?

You have to run it from command line.
Start->run->cmd

cxfreeze hello.py --target-dir dist
do I have to save it in a certain spot because It's just keeps telling me invalid syntax

This is more a pseudo explations,and will off course give you and syntak error if you dont change it.

E:\1py\freeze>python my_cx_freeze.py build #This is the line that start build process
(Your path)python my_cx_freeze.py build    #Change to wish dir you like

This run the my_cx_freeze.py that has a link to the program i want to make exe of.
Wish is in my case was date.py

Don't make the things more difficult.

1 - install cx_freeze.

2 - Open windows command shell, and navigate to your python install dir, then to scripts inside that dir.

3 - Type cxfreeze plus your path and script name, something like this:

cxfreeze d:\scripts\hello.py

4 - It will create a dir called dist with the files ready.

And you are done.

No need to do a setup script, or any modification to your script.

Have you look at my post it should be clear?

You have to run it from command line.
Start->run->cmd

This is more a pseudo explations,and will off course give you and syntak error if you dont change it.

E:\1py\freeze>python my_cx_freeze.py build #This is the line that start build process
(Your path)python my_cx_freeze.py build    #Change to wish dir you like

This run the my_cx_freeze.py that has a link to the program i want to make exe of.
Wish is in my case was date.py

I am using command line and I tried using the line of code you gave me and it gives me syntax error: invalid syntax

I am using command line and I tried using the line of code you gave me and it gives me syntax error: invalid syntax

Then you are doing something wrong,what we dont know because you dont post any code.
We are not mindreaders.

Example command for a script file 'protein.py' in directory 'D:\scripts\protein\', the executable file will be created in 'D:\scripts\protein\exe'.

cxfreeze d:\scripts\protein\protein.py --target-dir d:\scripts\protein\exe

Demonstration on Windows XP with Python 2.6.

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Beat_Slayer>cd c:\python26\scripts

C:\Python26\Scripts>cxfreeze d:\scripts\protein\protein.py --target-dir d:\scripts\protein\exe
creating directory d:\scripts\protein\exe
copying C:\Python26\lib\site-packages\cx_Freeze\bases\Console.exe -> d:\scripts\protein\exe\protein.exe
copying C:\WINDOWS\system32\python26.dll -> d:\scripts\protein\exe\python26.dll
writing zip file d:\scripts\protein\exe\protein.exe

  Name                      File
  ----                      ----
m StringIO
m UserDict
m __builtin__
m __future__
m __main__                  d:\scripts\protein\protein.py
m _abcoll
m _bisect
m _codecs
m _codecs_cn
m _codecs_hk
m _codecs_iso2022
m _codecs_jp
m _codecs_kr
m _codecs_tw
m _collections
m _functools
m _heapq
m _locale
m _multibytecodec
m _random
m _sre
m _strptime
m _struct
m _subprocess
m _threading_local
m _warnings
m abc
m array
m base64
m bdb
m binascii
m bisect
m bz2                       C:\Python26\DLLs\bz2.pyd
m cPickle
m cStringIO
m calendar
m cmd
m codecs
m collections
m copy
m copy_reg
m cx_Freeze__init__         C:\Python26\lib\site-packages\cx_Freeze\initscripts\
Console.py
m datetime
m difflib
m dis
m doctest
m dummy_thread
P encodings
m encodings.aliases
m encodings.ascii
m encodings.base64_codec
m encodings.big5
m encodings.big5hkscs
m encodings.bz2_codec
m encodings.charmap
m encodings.cp037
m encodings.cp1006
m encodings.cp1026
m encodings.cp1140
m encodings.cp1250
m encodings.cp1251
m encodings.cp1252
m encodings.cp1253
m encodings.cp1254
m encodings.cp1255
m encodings.cp1256
m encodings.cp1257
m encodings.cp1258
m encodings.cp424
m encodings.cp437
m encodings.cp500
m encodings.cp737
m encodings.cp775
m encodings.cp850
m encodings.cp852
m encodings.cp855
m encodings.cp856
m encodings.cp857
m encodings.cp860
m encodings.cp861
m encodings.cp862
m encodings.cp863
m encodings.cp864
m encodings.cp865
m encodings.cp866
m encodings.cp869
m encodings.cp874
m encodings.cp875
m encodings.cp932
m encodings.cp949
m encodings.cp950
m encodings.euc_jis_2004
m encodings.euc_jisx0213
m encodings.euc_jp
m encodings.euc_kr
m encodings.gb18030
m encodings.gb2312
m encodings.gbk
m encodings.hex_codec
m encodings.hp_roman8
m encodings.hz
m encodings.idna
m encodings.iso2022_jp
m encodings.iso2022_jp_1
m encodings.iso2022_jp_2
m encodings.iso2022_jp_2004
m encodings.iso2022_jp_3
m encodings.iso2022_jp_ext
m encodings.iso2022_kr
m encodings.iso8859_1
m encodings.iso8859_10
m encodings.iso8859_11
m encodings.iso8859_13
m encodings.iso8859_14
m encodings.iso8859_15
m encodings.iso8859_16
m encodings.iso8859_2
m encodings.iso8859_3
m encodings.iso8859_4
m encodings.iso8859_5
m encodings.iso8859_6
m encodings.iso8859_7
m encodings.iso8859_8
m encodings.iso8859_9
m encodings.johab
m encodings.koi8_r
m encodings.koi8_u
m encodings.latin_1
m encodings.mac_arabic
m encodings.mac_centeuro
m encodings.mac_croatian
m encodings.mac_cyrillic
m encodings.mac_farsi
m encodings.mac_greek
m encodings.mac_iceland
m encodings.mac_latin2
m encodings.mac_roman
m encodings.mac_romanian
m encodings.mac_turkish
m encodings.mbcs
m encodings.palmos
m encodings.ptcp154
m encodings.punycode
m encodings.quopri_codec
m encodings.raw_unicode_escape
m encodings.rot_13
m encodings.shift_jis
m encodings.shift_jis_2004
m encodings.shift_jisx0213
m encodings.string_escape
m encodings.tis_620
m encodings.undefined
m encodings.unicode_escape
m encodings.unicode_internal
m encodings.utf_16
m encodings.utf_16_be
m encodings.utf_16_le
m encodings.utf_32
m encodings.utf_32_be
m encodings.utf_32_le
m encodings.utf_7
m encodings.utf_8
m encodings.utf_8_sig
m encodings.uu_codec
m encodings.zlib_codec
m errno
m functools
m gc
m genericpath
m getopt
m gettext
m heapq
m imp
m inspect
m itertools
m keyword
m linecache
m locale
m marshal
m math
m msvcrt
m nt
m ntpath
m opcode
m operator
m optparse
m os
m pdb
m pickle
m posixpath
m pprint
m quopri
m random
m re
m repr
m select                    C:\Python26\DLLs\select.pyd
m shlex
m signal
m sre_compile
m sre_constants
m sre_parse
m stat
m string
m stringprep
m strop
m struct
m subprocess
m sys
m tempfile
m textwrap
m thread
m threading
m time
m token
m tokenize
m traceback
m types
m unicodedata               C:\Python26\DLLs\unicodedata.pyd
m unittest
m warnings
m zipimport
m zlib

copying C:\Python26\DLLs\bz2.pyd -> d:\scripts\protein\exe\bz2.pyd
copying C:\Python26\DLLs\select.pyd -> d:\scripts\protein\exe\select.pyd
copying C:\Python26\DLLs\unicodedata.pyd -> d:\scripts\protein\exe\unicodedata.p
yd

C:\Python26\Scripts>dir d:\scripts\protein\exe
 Volume in drive D is Professional
 Volume Serial Number is 689E-FA9B

 Directory of d:\scripts\protein\exe

15-07-2010  22:07    <DIR>          .
15-07-2010  22:07    <DIR>          ..
15-07-2010  22:07            71.680 bz2.pyd
15-07-2010  22:07         1.425.114 protein.exe
15-07-2010  22:07         2.145.280 python26.dll
15-07-2010  22:07            11.776 select.pyd
15-07-2010  22:07           585.728 unicodedata.pyd
               5 File(s)      4.239.578 bytes
               2 Dir(s)   5.199.376.384 bytes free

C:\Python26\Scripts>

this is what I have in my module
[import time
print('Hello World!!!!')
time.sleep(1)
print ('what is your name?')
name = input()
a = ('Hello ')
b = (' my name is com')
string = a+name +b
print (string)
time.sleep(2)
print('What is your favorite color?')
color = input()
c= ('Thats awesome ')
print(c+name)
time.sleep(2)
d=(' is my favorite color too')
print(color+d)
time.sleep(2.7)
e =('bye ')
print(e+name)]

and this is what my command looks like

[>>>E:\1py\freeze>python my_cx_freeze.py build
file "<stdin>", line1
E:\freeze>python my_cx_freeze.py build
syntaxError: invalid syntax]

this is what I have in my module

Push the (CODE) button before pasting, please!

import time
print('Hello World!!!!')
time.sleep(1)
print ('what is your name?')
name = input()
a = ('Hello ')
b = (' my name  is com')
string = a+name +b
print (string)
time.sleep(2)
print('What is your favorite color?')
color = input()
c= ('Thats awesome  ')
print(c+name)
time.sleep(2)
d=(' is my favorite color too')
print(color+d)
time.sleep(2.7)
e =('bye ')
print(e+name)]

and this is what my command looks like

>>>E:\1py\freeze>python my_cx_freeze.py build
   file "<stdin>", line1
     E:\freeze>python my_cx_freeze.py build
syntaxError: invalid syntax

>>>E:\1py\freeze>python my_cx_freeze.py build

You are running from IDLE python shell,that`s not command line.
Dont you understand what command line is?

Windows you push start->run(write cmd)
Then command shell start.
Then you navigate using cd to the dir where you have your py-files.

correct me if Im wrong but idle doesnt have black background in it so Im pretty sure its called command line espically for the part that I clicked on a button that said command line

Specify which platform you are and how you start exactly. Are you sure you do not mix command line with Python command line?

Command lines usually prompt with current directory path:

Microsoft Windows XP [versio 5.1.2600]
(C) Copyright 1985 - 2001 Microsoft Corp.

C:\Documents and Settings\Veijalaiset>

But for example Python interpreter shell gives you like this:

Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

oh ive never heard of it do you have to download it or is it already on your computer

Click on "Start", select "Run" and type "command"!

I found It and tried some of the codes you posted earlier. Then later I looked at my files and I had four different modules compiled to .pyc file types and I thought they were supposed to be .exe

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.