Python Forum
cx_Freeze doesn't seem to work
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cx_Freeze doesn't seem to work
#1
I cannot get cx_Freeze to work at all and keep getting, when I try to build the exe file, the same error: "No module named cx_Freeze.util" 

Im using Python 3.52 on Windows 10. I downloaded cx_Freeze 5.0 from Sourceforge, and among other things got the scripts hello.py and setup.py in the folder C:\Users\Owen Walker\AppData\Local\Programs\Python\Python35-32\Lib\site-ackages\cx_Freeze\samples\simple. 

When I run, in that folder on the Windows 10 command line, python setup.py build, I get this error:

 "File "C:\Users\Owen Walker\AppData\Local\Programs\Python\Python35-32\Lib\site-packages\cx_Freeze\freezer.py", line 256 in _GetDefaultBinPathExcludes import cx_Freeze.util

No module named cx_Freeze.util"

cx_Freeze seems so straightforward that I can't believe I can't make it work even in this simple instance.

Help in compiling this simple hello.py script into a Windows .exe would be greatly appreciated.


Owen Walker
Reply
#2
1) post your setup script
2) Post your program. What 3rd party libs are you using in your program?

Have you tried the others? Py2exe or PyInstaller? When you get one to work people just usually leave it alone and use that from there on out. 

The more 3rd party libs and the more code you have on your program the more problems that can arise. If you are using a 3rd party lib, try building an exe from a basic hello world script and see if you get the same error. 
http://python-forum.io/Thread-Intermedia...ing+an+exe
Recommended Tutorials:
Reply
#3
hello.py is

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from datetime import datetime
import sys
from sys import stdout
stdout.write('Hello from cx_Freeze\n')
stdout.write('The current date is %s\n\n' %
             datetime.today().strftime('%B %d, %Y %H:%M:%S'))
stdout.write('Executable: %r\n' % sys.executable)
stdout.write('Prefix: %r\n' % sys.prefix)
stdout.write('File system encoding: %r\n\n' % sys.getfilesystemencoding())
stdout.write('ARGUMENTS:\n')
for a in sys.argv:
    stdout.write('%s\n' % a)
stdout.write('\n')
stdout.write('PATH:\n')
for p in sys.path:
    stdout.write('%s\n' % p)
stdout.write('\n')
The two files, hello.py and setup.py came with cx_Freeze when I downloaded it and therefore should be in proper form.



setup.py is

# -*- coding: utf-8 -*-
# A very simple setup script to create a single executable
#
# hello.py is a very simple 'Hello, world' type script which also displays the
# environment in which the script runs
#
# Run the build process by running the command 'python setup.py build'
#
# If everything works well you should find a subdirectory in the build
# subdirectory that contains the files needed to run the script without Python
from cx_Freeze import setup, Executable
executables = [
    Executable('hello.py')
]
setup(name='hello',
      version='0.1',
      description='Sample cx_Freeze script',
      executables=executables
      )
I have previously had no luck with py2exe or pyinstaller, which evidently work only with python 2.

Thanks.
Reply
#4
(Jan-02-2017, 06:55 PM)owenwalker65 Wrote: I have previously had no luck with py2exe or pyinstaller, which evidently work only with python 2.
That is not true. I have personally built exe's with python3.x in py2exe
Recommended Tutorials:
Reply
#5
Testet with 3.5 and 3.6 and it work.
I use wheel from gohlke.

The default path is horrible,i would reinstall and choose a path like C:\python35
Make sure that add python 3.5 to PATH and pip is marked on.
Restart pc.

Files:
#hello_cx.py
from datetime import datetime

print('Hello from cx_Freeze')
print('The current date is {}'.
     format(datetime.today().strftime('%B %d, %Y %H:%M:%S')))
#make_exe.py
from cx_Freeze import setup,Executable
import sys

# Replaces commandline arg 'build'
#sys.argv.append("build")

# If need to include/exclude module/packages
includes = []
excludes = []
packages = []

# Console or Win32GUI
base = None
if sys.platform == "win32":
    base = 'Console'
    #base = 'Win32GUI'

# Name of file to make ".exe" of
filename = "hello_cx.py"
setup(
    name = 'Myapp',
    version = '0.1',
    description = 'Cx test',
    options = {'build_exe': {'excludes':excludes,'packages':packages,'includes':includes}},
    executables = [Executable(filename, base=base, icon = None)])

# From command line
#python make_exe.py build
I do run it from virtual environment(it's now build in 3.5).
Here is the whole process(shell is cmder).

# make virtual environment 
C:\Python35
λ python -m venv cx_test

C:\Python35
λ cd cx_test/scripts

C:\Python35\cx_test\Scripts
λ C:\Python35\cx_test\Scripts\activate.bat

(cx_test) C:\Python35\cx_test\Scripts
λ pip install cx_Freeze-5.0-cp35-cp35m-win32.whl
Processing c:\python35\cx_test\scripts\cx_freeze-5.0-cp35-cp35m-win32.whl
Installing collected packages: cx-Freeze
Successfully installed cx-Freeze-5.0

(cx_test) C:\Python35\cx_test\Scripts
λ python make_exe.py build
# A lot of files

(cx_test) C:\Python35\cx_test\Scripts
λ cd build\exe.win32-3.5

# Test exe
(cx_test) C:\Python35\cx_test\Scripts\build\exe.win32-3.5
λ hello_cx.exe
Hello from cx_Freeze
The current date is January 03, 2017 00:44:34
Quote:I have previously had no luck with py2exe or pyinstaller, which evidently work only with python 2.
pyinstaller was the first one that worked for 3.5.
py2exe work up to 3.4.
Reply
#6
what does code below means?
includes = []
excludes = []
packages = []
Reply
#7
They are for include module/package and other stuff that may be needed in build posses.
Example this was needed to get pyttsx to work.
#cx_run.py
from cx_Freeze import setup,Executable

includes = ["pyttsx", "pyttsx.drivers.sapi5"]
excludes = []
packages = ['win32com.gen_py']

filename = "sound_test.py"
setup(
    name = 'myapp',
    version = '0.1',
    description = 'test pyttsx',
    author = 'no',
    author_email = '[email protected]',
    options = {'build_exe': {'excludes':excludes,'packages':packages,'includes':includes}},
    executables = [Executable(filename, base = "Win32GUI", icon = None)])
Reply
#8
(Dec-06-2017, 05:49 PM)snippsat Wrote: They are for include module/package and other stuff that may be needed in build posses.
Example this was needed to get pyttsx to work.
#cx_run.py
from cx_Freeze import setup,Executable

includes = ["pyttsx", "pyttsx.drivers.sapi5"]
excludes = []
packages = ['win32com.gen_py']

filename = "sound_test.py"
setup(
    name = 'myapp',
    version = '0.1',
    description = 'test pyttsx',
    author = 'no',
    author_email = '[email protected]',
    options = {'build_exe': {'excludes':excludes,'packages':packages,'includes':includes}},
    executables = [Executable(filename, base = "Win32GUI", icon = None)])

how should I put the module and etc ?
i do have some module as below
from tkinter import *
from tkinter import filedialog 
import tkinter.ttk as ttk
import os
import pandas as pd  
import glob
from pandas import ExcelWriter
from pandas import ExcelFile
import time, sys
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Convolution "same" in Python doesn't work as Matlab claw91 4 3,686 Oct-01-2020, 08:59 AM
Last Post: claw91
  Numpy doesn't work in Spyder 4.1.3 player1681 1 2,103 Jun-02-2020, 11:26 AM
Last Post: jefsummers
  scipy interp2d doesn't work player1681 4 4,402 Feb-05-2020, 09:50 AM
Last Post: player1681
  cx_freeze exe does nothing taigi100 0 2,660 Jul-08-2018, 02:11 PM
Last Post: taigi100
  cx_freeze exe error issac_n 0 3,292 Dec-07-2017, 10:08 AM
Last Post: issac_n
  cx_freeze setup.py TCL_LIBRARY error issac_n 0 3,754 Dec-05-2017, 10:40 AM
Last Post: issac_n
  Matplotlib Doesn't Work Ian12290 6 13,140 Feb-28-2017, 06:18 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020