(Aug-23-2018, 07:34 AM)Axel_Erfurt Wrote: you forgot to import build ?There is no need to import build,it's only needed from command line.
@ahmed_mokhles can show a run with Cx_Freeze as i used many times in the past.
Build a virtual environment with 3.6 as 3.7 is my main setup.
Virtual environment(build into 3.6 -->) can be great for troubleshooting,if there is a problem with build.
# Make enviroment E:\div_code λ py -3.6 -m venv cx_env # Cd in E:\div_code λ cd cx_env # Activate E:\div_code\cx_env λ E:\div_code\cx_env\Scripts\Activate # Install cx_Freeze (cx_env) E:\div_code\cx_env λ pip install cx_Freeze Collecting cx_Freeze Downloading https://files.pythonhosted.org/packages/3b/04/d68567b8f3265d3936e37c1ee8b3378dc189ec66b4d43650affbefcc69c5/cx_Freeze-5.1.1-cp36-cp36m-win32.whl (175kB) 100% |████████████████████████████████| 184kB 853kB/s Installing collected packages: cx-Freeze Successfully installed cx-Freeze-5.1.1 # Install win32 (cx_env) E:\div_code\cx_env λ pip install pypiwin32 Collecting pypiwin32 Using cached https://files.pythonhosted.org/packages/d0/1b/2f292bbd742e369a100c91faa0483172cd91a1a422a6692055ac920946c5/pypiwin32-223-py3-none-any.whl Collecting pywin32>=223 (from pypiwin32) Using cached https://files.pythonhosted.org/packages/d4/2d/b927e61c4a2b0aaaab72c8cb97cf748c319c399d804293164b0c43380d5f/pywin32-223-cp36-cp36m-win32.whl Installing collected packages: pywin32, pypiwin32 Successfully installed pypiwin32-223 pywin32-223 (cx_env) E:\div_code\cx_env λ ls Include/ Lib/ Scripts/ coin_toss.py cx_run.py pip-selfcheck.jsonAt this point all is done from
cx_env
folder,so no path should be given.# cx_run.py from cx_Freeze import setup,Executable import sys # 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 = "coin_toss.py" setup( name = 'Myapp', version = '0.1', description = 'Toss a coin', options = {'build_exe': {'excludes':excludes,'packages':packages,'includes':includes}}, executables = [Executable(filename, base=base, icon = None)]) # --- From command line --- #python cx_run.py buildThe example code used before in post with Pyinstaller.
# coin_toss.py import random import time class Coin: def __init__(self): self.sideup = "Heads" def toss(self): if random.randrange(2) == 0: self.sideup = "Heads" else: self.sideup = "Tails" def toss_result(): my_coin = Coin() print(f"This side is up: {my_coin.sideup}") print("I am tossing the coin...") time.sleep(4) my_coin.toss() print(f"This side is up: {my_coin.sideup}") input('Press Enter to exit') if __name__ == "__main__": toss_result()See that
base = 'Console'
because this is not a GUI code.From command line build and test
coin_toss.exe
.# Build exe (cx_env) E:\div_code\cx_env λ python cx_run.py build running build running build_exe .... # Cd in (cx_env) E:\div_code\cx_env λ cd build\ (cx_env) E:\div_code\cx_env\build λ cd exe.win32-3.6\ # exe placement (cx_env) E:\div_code\cx_env\build\exe.win32-3.6 λ ls coin_toss.exe* lib/ python36.dll* # Test it works (cx_env) E:\div_code\cx_env\build\exe.win32-3.6 λ coin_toss.exe This side is up: Heads I am tossing the coin... This side is up: Tails Press Enter to exit (cx_env) E:\div_code\cx_env\build\exe.win32-3.6 λ