As we complete a Python project or a program, we want to package Python's py files into EXE programs that can run directly under Windows systems. In view of the information on the Internet, there is a way to use Pyinstaller and Cx_freeze to pack. For Cx_freeze Packaging, refer to Wangdamozhizhou blog Windows Cx_freeze generate a method in the Python executable program. Because the method is primarily available for Python3.3 versions, Python above this version is not available. In the course of my attempts, one of the problems encountered is:
Install cx_freeze-4.3.3, Cxfreeze.bat not found
The solution is that, under the CMD command line operation, switch to the scripts directory under the Python installation directory where cx_freeze-4.3.3 files are placed, and use the following code to automatically generate:
Python Cxfreeze-postinstall
Since the Python version I installed is version 3.6.2, the version is relatively new, Cx_freeze has not yet updated the version to version 3.6. After I tried many times to fail, I decided to use Pyinstaller to package the files.
Download Pyinstaller using command Line Operations in the cmd command line, enter the code:
Pip Install Pyinstaller
Or use the update, upgrade method:
Pip Install--upgrade Pyinstaller
the method of +cmd operation by downloading filesFirst, go to Pyinstaller website to download: http://www.pyinstaller.org/downloads.html
When downloading, be aware of how many versions of Python you have installed, the stable and the unstable version, Python3.6 only unstable versions. The green boxes are available under the Linux operating system, and the red boxes apply to Windows.
for decompression, placement, and installationAfter downloading, unzip the compressed file into the Python installation directory and enter the file:
The directory contains setup.py and enters the directory in cmd:
Enter command:
Python setup.py Install
and press ENTER, you will see the code to execute quickly, will be installed Pyinstaller, display the following status, see "Finished processing dependencies for pyinstaller==3.3.dev0+41c426f6d", The installation is successful:
using Pyinstaller to package py files into EXE programs
packaged files into EXE programSwitch the cmd directory to (command: the CD file path (note space) in the folder of the py file directory you want to package:
and enter the code, in the format of the use command: pyinstaller-f filename (with suffix py):
Pyinstaller-f test.py
Common parameter Description:
–icon= icon Path
-F packaged into an EXE file
-W using windows, no console
-C Use console, no window
-D Create a directory containing EXE and some other dependency files
Pyinstaller-h to view parameters
After the carriage return, the code operates quickly until the operation is finished.
Returns the destination file directory, where the. spec file Test.spec was found in the directory:
Packaged exe files, in the same directory as the dist file:
Thus, the PY file is packaged as an EXE file.
Pyinstaller Change the icon of the generated EXE program
Pyinstaller-f--icon=my.ico test.py
My.ico is an icon name, and the current test.py file is in the same directory