SHARE
TWEET

Untitled

a guest Jun 25th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from os import environ, system, remove, listdir, path, __file__
  2. from shutil import move, rmtree
  3.  
  4. program_name = "Name of the Game"
  5. # name of the program
  6. main_file = "main.py"
  7. # the main file that will turn into the exe
  8. libraries_used = ["pygame"]
  9. # add all the libraries used here e.g. pygame, random
  10. files_needed = ["images", "sounds", "functions.py"]
  11. # this is all the files that you are using can be folders or files
  12. program_description = "This program..."
  13. # program discription
  14. program_version = "0.0.1"
  15. # this is the program version
  16.  
  17.  
  18. code = f"""\
  19. import cx_Freeze
  20.  
  21. cx_Freeze.setup(
  22.     name="{program_name}",
  23.     version = "{program_version}",
  24.     description = "{program_description}",
  25.     options={{"build_exe": {{"packages": {libraries_used},
  26.                            "include_files": {files_needed}}}}},
  27.     executables=[cx_Freeze.Executable("{main_file}")]
  28.  
  29. )
  30. """
  31.  
  32. with open("setup.py", 'w') as setup_file:
  33.     setup_file.write(code)
  34.  
  35. python_path = path.dirname(path.dirname(__file__))
  36. python = path.join(python_path, "python")
  37. pip = path.join(python_path, "Scripts", "pip")
  38.  
  39. environ['TCL_LIBRARY'] = path.join(python_path, "tcl", 'tcl8.6')
  40. environ['TK_LIBRARY'] = path.join(python_path, "tcl", 'tk8.6')
  41.  
  42. libraries_used.append("cx_Freeze")
  43. system(f"{python} -m pip install --upgrade pip")
  44. for i in libraries_used:
  45.     system(f"{pip} install {i}")
  46.  
  47. #system(f"{python} setup.py build")  # for having just the exe
  48. system(f"{python} setup.py bdist_msi")  # for creating msi installer
  49. #system(f"{python} setup.py bdist_dmg")  # only on mac create an installer
  50.  
  51. remove("setup.py")
  52.  
  53. # this part down here leaves only the installer
  54. for i in listdir("dist"):
  55.     move(f"dist/{i}", f"{i}")
  56. rmtree("dist")
  57. rmtree("build")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top