Hello everyone, I am a ruffian balance, is a serious technical ruffian. Today ruffian balance to introduce you is the serial port debugging tool Pzh-py -com was born of the package released.

After the last software optimization, pzh-py-com has been initially grown, the time to go out experience, only experienced the masses of software is qualified software. PZH PZH PZH PZH PZH PZH PZH PZH PZH PZH PZH PZH PZH PZH PZH PZH PZH PZH PZH PZH PZH PZH PZH PZH PZH PZH PZH PZH The answer, of course, is no, because if it were, pzh-py-com would be almost impossible to use. In order for someone else to run pzh-py-com without a special environment, we need to package pzh-py-com as a stand-alone executable. In this case, we need to use a specialized Python packaging tool. This is the last part of the series. Ruffian balance for you to talk about how to use the packaging tool package Pzh-py-com to release.

Introduction to PyInstaller

There are many Python package tools, such as Py2exe, cx_Freeze, and PyInstaller. PyInstaller was created in 2005 and has been updated to v3.x over the years.

PyInstaller official home: www.pyinstaller.org/ PyInstaller Github home: github.com/pyinstaller…

Before using PyInstaller to package, you need to make sure that all third-party libraries your Python application calls are in the PyInstaller support list. This home page shows all third-party libraries supported by PyInstaller: Github.com/pyinstaller… Django, Numpy, PyGame, PyOpenGL, PyQt, PyWin32, etc. PyInstaller is very simple to use. Read the official documentation first. -f, -w, -i, and.spec files are all you need to package pzh-py-com.

PyInstaller official documentation homepage: readthedocs.org/projects/py… PyInstaller 3.3.1 command to fit: PyInstaller. Readthedocs. IO/en/v3.3.1 / u… PyInstaller 3.3.1 spec file: PyInstaller. Readthedocs. IO/en/v3.3.1 / s…

Package pzh-py-com

PZH – PZH – PZH – PZH – PZH – PZH – PZH – PZH – PZH – PZH – PZH – PZH

\pzh-py-com \. Idea -- Place PyCharm project \bin -- Place exe file \ GUI -- Place GUI design file \pzh-py-com. FBP --wxFormBuilder project file \img PNG led_green. PNG logo_merge. JPG SRC -- Put project source file formatter.py -- Project linker file main.py -- Board-level source files (such as pinout, clock, etc.) \win.py --wxPython window source files (generated by wxFormBuilder)Copy the code

2.1 Packing Preparations

Since there are only six source files for the pzh-py-com application, all ready to go, and the pySerial and wxPython libraries that pzh-py-com relies on are in the PyInstaller list, the only preparation left is to make the pzh-py-com icon file. To make an icon file, you first have to have an image file. Riffracken took part of pySerial’s logo and used it as the pzh-py-com icon. With the image, you can convert it to an icon file (.ico) using the website converticon.com/. After making the icon file, place it in the \pzh-py-com\img\ directory:

PNG \pzh-py-com.ico \pzh-py-com.ico \pzh-py-com.ico \pzh-py-com.icoCopy the code

2.2 Starting Packing

Before using PyInstaller to package, it is important to understand that PyInstaller can only package.py source files and their associated Python third-party source libraries into a final.exe file. If your application uses images or other multimedia files, These multimedia files cannot be packaged, they must be present for subsequent use of the EXE, and must be consistent with the relative path of packaging/development. Pzh-py-com: pystaller -f -w [src1.py] [src2.py] pzh-py-com: pystaller -f -w [src1.py] [src2.py] -i [pic.ico], to explain the command combination, -f means to package the application as a single executable (the opposite is -d, packaged as multiple files in a folder), -w means to package the application as a window (the opposite is -c, console), [src1.py][src2.py][…] For the application source file you created for yourself (src1.py must be the main function file containing __main__), -i specifies the icon file.

PS D:\my_git_repo\pzh-py-com\bin> pyinstaller -F -w .. \src\main.py .. \src\formatter.py .. \src\win.py -i .. \img\pzh-py-com.ico

223 INFO: PyInstaller: 3.3.1
225 INFO: Python: 2.7.14
227 INFO: Platform: Windows-10-10.0.15063
230 INFO: wrote D:\my_git_repo\pzh-py-com\bin\main.spec
233 INFO: UPX is not available.
237 INFO: Extending PYTHONPATH with paths
['D:\\my_git_repo\\pzh-py-com\\bin',
Copy the code

‘D:\my_git_repo\pzh-py-com\src’,

‘D:\my_git_repo\pzh-py-com\src’,

‘D:\my_git_repo\pzh-py-com\src’]

238 INFO: checking Analysis 240 INFO: Building Analysis because out00-Analysis.toc is non existent 240 INFO: Initializing module dependency graph… 246 INFO: Initializing module graph hooks… 323 INFO: running Analysis out00-Analysis.toc 342 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable required by c:\tools_mcu\python27\python.exe 5611 INFO: Found C: \ WINDOWS \ WinSxS \ Manifests \ amd64_policy 9.0. Microsoft. Vc90. Crt_1fc8b3b9a1e18e3b_9. 0.30729.1 _none_3da38fdebd0e6822. Manif est 5615 INFO: Found C: \ WINDOWS \ WinSxS \ Manifests \ amd64_policy 9.0. Microsoft. Vc90. Crt_1fc8b3b9a1e18e3b_9. 0.30729.6161 _none_acd388d7e1d8689f. Ma nifest 5621 INFO: Found C: \ WINDOWS \ WinSxS \ Manifests \ amd64_policy 9.0. Microsoft. Vc90. Crt_1fc8b3b9a1e18e3b_9. 0.30729.9279 _none_acd3d86fe1d846c4. Ma Nifest 5825 INFO: Searching for Assembly amd64_microsoft.vc90. crt_1fc8b3B9a1e18e3b_9.0.30729.9279 _none… Searching for Assembly amd64_Microsoft.vc90. crt_1FC8b3B9A1e18e3B_9.0.30729.9279 _none… 5826 INFO: Found manifest C: \ WINDOWS \ WinSxS \ Manifests \ amd64_microsoft vc90. Crt_1fc8b3b9a1e18e3b_9. 0.30729.9279 _none_08e667efa83ba076. Manifest 5828 INFO: Searching for file msvcr90.dll 5829 INFO: Found the file C: \ WINDOWS \ WinSxS \ amd64_microsoft vc90. Crt_1fc8b3b9a1e18e3b_9. 0.30729.9279 _none_08e667efa83ba076 \ msvcr90 DLL 5830 INFO: Searching for file msvcp90.dll 5832 INFO: Found the file C: \ WINDOWS \ WinSxS \ amd64_microsoft vc90. Crt_1fc8b3b9a1e18e3b_9. 0.30729.9279 _none_08e667efa83ba076 \ msvcp90 DLL 5833 INFO: Searching for file msvcm90.dll 5835 INFO: Found the file C: \ WINDOWS \ WinSxS \ amd64_microsoft vc90. Crt_1fc8b3b9a1e18e3b_9. 0.30729.9279 _none_08e667efa83ba076 \ msvcm90 DLL 6032 INFO: Found C: \ WINDOWS \ WinSxS \ Manifests \ amd64_policy 9.0. Microsoft. Vc90. Crt_1fc8b3b9a1e18e3b_9. 0.30729.1 _none_3da38fdebd0e6822. Manif est 6033 INFO: Found C: \ WINDOWS \ WinSxS \ Manifests \ amd64_policy 9.0. Microsoft. Vc90. Crt_1fc8b3b9a1e18e3b_9. 0.30729.6161 _none_acd388d7e1d8689f. Ma nifest 6034 INFO: Found C: \ WINDOWS \ WinSxS \ Manifests \ amd64_policy 9.0. Microsoft. Vc90. Crt_1fc8b3b9a1e18e3b_9. 0.30729.9279 _none_acd3d86fe1d846c4. Ma nifest 6037 INFO: Adding redirect Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9279) 6175 INFO: Caching module hooks… 6180 INFO: Analyzing D:\my_git_repo\pzh-py-com\src\main.py 8021 INFO: Analyzing D:\my_git_repo\pzh-py-com\src\formatter.py 8024 INFO: Analyzing D:\my_git_repo\pzh-py-com\src\win.py 8040 INFO: Loading module hooks… 8040 INFO: Loading module hook “hook-wx.xrc.py”… 8046 INFO: Loading module hook “hook-encodings.py”… 8750 INFO: Looking for ctypes DLLs 8758 INFO: Analyzing run-time hooks … 8766 INFO: Looking for dynamic libraries 9258 INFO: Looking for eggs 9258 INFO: Using Python library C:\WINDOWS\system32\python27.dll 9260 INFO: Found binding redirects: [BindingRedirect(name=u’Microsoft.VC90.CRT’, language=None, arch=u’amd64′, oldVersion=(9, 0, 21022, 8), newVersion=(9, 0, 30729, 9279), publicKeyToken=u’1fc8b3b9a1e18e3b’)] 9264 INFO: Warnings written to D:\my_git_repo\pzh-py-com\bin\build\jayspycom_main\warnjayspycom_main.txt 9287 INFO: Graph cross-reference written to D:\my_git_repo\pzh-py-com\bin\build\jayspycom_main\xref-jayspycom_main.html 9329 INFO: checking PYZ 9329 INFO: Building PYZ because out00-PYZ.toc is non existent 9330 INFO: Building PYZ (ZlibArchive) D:\my_git_repo\pzh-py-com\bin\build\main\out00-PYZ.pyz 9608 INFO: Building PYZ (ZlibArchive) D:\my_git_repo\pzh-py-com\bin\build\main\out00-PYZ.pyz completed successfully. 9648 INFO: checking PKG 9649 INFO: Building PKG because out00-PKG.toc is non existent 9651 INFO: Building PKG (CArchive) out00-PKG.pkg 9796 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9279) 14667 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully. 14674 INFO: Bootloader c:\tools_mcu\python27\lib\site-packages\PyInstaller\bootloader\Windows-64bit\runw.exe 14674 INFO: checking EXE 14677 INFO: Building EXE because out00-EXE.toc is non existent 14678 INFO: Building EXE from out00-EXE.toc 14695 INFO: SRCPATH [(‘..\img\jayspycom.ico’, None)] 14697 INFO: Updating icons from [‘..\img\pzh-py-com.ico’] to c:\users\nxa07314\appdata\local\temp\1\tmpcvu1zy 14698 INFO: Writing RT_GROUP_ICON 0 resource with 20 bytes 14698 INFO: Writing RT_ICON 1 resource with 4264 bytes 14707 INFO: Appending archive to EXE D:\my_git_repo\pzh-py-com\bin\dist\main.exe 14724 INFO: Building EXE from out00-EXE.toc completed successfully.

After the package command is successfully executed, you can see the following generated files in the \pzh-py-com\bin directory: Text \pzh-py-com \bin -- place project source file \build\ -- dist\main.exe -- executable exe file \main.spec --spec fileCopy the code

The build folder stores the debugging files generated by PyInstaller during the packaging process. The main. Exe folder below the dist folder is the final executable file we need. The commands you type on the command line are first translated into a.spec file, and PyInstaller is packaged with the.spec file. You can use the PyInstaller main.spec command to package the file again and get the same results. So here’s what’s in the.spec file, and if you’re familiar with.spec files, of course you can create your own.

# -*- mode: python -*- block_cipher = None a = Analysis(['main.py', 'formatter.py', 'win.py'], binaries=[], datas=[], hiddenimports=[], hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher) pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) exe = EXE(pyz, a.scripts, a.binaries, a.zipfiles, a.datas, name='pzh-py-com', debug=False, strip=False, upx=True, runtime_tmpdir=None, console=False , icon='.. \\img\\pzh-py-com.ico')Copy the code

[pzh-py-com\bin\dist\] [pzh-py-com\bin\dist\] [pzh-py-com\bin\dist\] [pzh-py-com\bin\dist\] [pzh-py-com\bin\dist\] [pzh-py-com\bin\dist\] Ruffian balance in fact has been mentioned in front, the need to ensure that the folder image relative path and packaging relative path consistent, try to main.exe in\ pzh-py-com\bin\ directory and then open to see if it is normal, because at this time the relative path is consistent. That’s it. Finally, rename main.exe to pzh-py-com.exe.

Set pieces

The final pzh-py-com.exe file must be used with the pzh-py-com folder, and the pzh-py-com.exe file must not be moved in the pzh-py-com folder. Pzh-py-com. exe is a workaround, but you can create a shortcut to pzh-py-com.exe on your desktop. Pzh-py-com. exe and run it in any directory. Pzh-py-com.exe is a file that can be loaded directly with the installer. Pyinstaller is a file that can be loaded directly with pzh-py-com.exe. Pzh-py -com.exe decodes the image data and saves it locally as a temporary image. After pzh-py-com.exe is started, the image can be loaded. Ideas, partners quickly start to try, this is ruffian Balance in the last lesson of this series to leave you a homework.

So far, serial debugging tool pzh-py-com birth package release ruffian balance will be introduced to the end, applause where ~~~

Welcome to subscribe to

The article will be published on my blog park homepage, CSDN homepage and wechat public account platform at the same time.

Wechat search “ruffian balance embedded” or scan the following two-dimensional code, you can see the first time on the phone oh.