[cx_Freeze] Build .exe they get more .py files, help needed ! - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: General (https://python-forum.io/forum-1.html) +--- Forum: News and Discussions (https://python-forum.io/forum-31.html) +--- Thread: [cx_Freeze] Build .exe they get more .py files, help needed ! (/thread-5392.html) |
[cx_Freeze] Build .exe they get more .py files, help needed ! - JamieVanCadsand - Oct-01-2017 Hey Programmers, Game Developers and Software Writers... I know how i can build .exes from an simgle .py file, but now i want to know, how i can build .exe (executable programs) from more imported .py files... I want to can write software they get more .py files imported they i write... I try to create executable programs they get more scripts imported (.py files), but i don't know how can i make an executable program with all my scripts they heart by my program, writted in python... Can anyone help me ?... Thanks, Jamie. RE: [cx_Freeze] Build .exe they get more .py files, help needed ! - snippsat - Oct-01-2017 A little basic. 1 python file that's imported is called a module .More than 1 file working together is often called a package .Using __init__.py as glue to navigate the file tree.So a game can have many files,and often a main python file that start the game. Can look a silly setup where more than one file work together. Folder setup: my_game/ |-- __init__.py |-- start_game.py sub_folder/ |-- __init__.py |-- game_module_1.py |-- game_module_2.pystart_game.py: import random import time from sub_folder import game_module_1, game_module_2 def game(): time.sleep(5) return random.choice([game_module_1.motor_1(), game_module_2.motor_2()]) print('Dos the motor start???') if game() == 'start motor': print('The motor did start') else: print('The motor did not start')__init__.py: from .sub_folder import motor_1 from .sub_folder import motor_2game_module_1.py: def motor_1(): return 'start motor'game_module_2.py: def motor_2(): return 'Stop motor'The __init__.py in sub folder is empty. Running this game:
RE: [cx_Freeze] Build .exe they get more .py files, help needed ! - JamieVanCadsand - Oct-02-2017 OK... that is whats i means with more .py files, but how do i build an .exe file with all .py files in one build, using cx_Freeze ?, that is just my question !... Can you tell me about how i can build just an .exe with all my .py files in one ?... Thanks, Jamie... RE: [cx_Freeze] Build .exe they get more .py files, help needed ! - snippsat - Oct-02-2017 You call the one file that start the game. As it's package all work together and other files are imported into start_game.py.Example Pyinstaller: I add one line so console window don't disappear. In a game or GUI there is main loop that run all time until exit. For console it's not like that. input('Press enter to exit')In my_game folder i run: (cx) C:\1\cx\my_game λ pyinstaller --onefile start_game.pyThere will be one start_game.exe in dist folder.cx_Freeze example. I change to base = 'Console' and call start_game.py.#cx_run.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 = "start_game.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 cx_run.py buildFrom command line: (cx) C:\1\cx\my_game λ python cx_run.py buildFor more on building stuff for Python like Wheel and use PyPi. Look at my tutorial here. |