Cx_freeze
Cx_freeze is a third-party library that can be used to package Python code into an executable file, and here's how to use a script file to turn Python code into an EXE executable file.
First, you need to install the Cx_freeze, you can use the PIP to install, the installation method is as follows
Pip Install Cx_freeze
After the installation is complete, create a setup.py file in the same directory as the code that needs to be packaged, enter the following code, where Build_exe_options is a dictionary of optional parameters, packages to the library to be included, excludes to the library that does not need to be included, Include_ Files is the file or folder that you want to include.
ImportSYS fromCx_freezeImportSetup, Executablebuild_exe_options= {"Packages": ["OS","pkg_resources"], "excludes": ["Tkinter"], "Include_files": ["icons/","scripts/"]}base=NoneifSys.platform = ="Win32": Base="Win32gui" #base = "Console"Setup (name="Test", Version= 1.0, Description="Python Test", Options= {"Build_exe": Build_exe_options}, Executables= [Executable ("test.py", Base=base)])
Once the configuration is complete, use CMD to open the command-line window and CD to the current directory, and enter the following command to execute the package.
Python setup.py Build
When finished, a build folder is generated under the directory, which contains the executable file.
Python Support Tools [1], executable file generation tool, Cx_freeze