Solve a Pit of Pyinstaller Packaging Software Failure

  • 2021-09-12 01:46:50
  • OfStack

Recently, I wrote a software that can't run normally after being packaged repeatedly, but it can be output normally when running directly in the command line window of cmd without any error. I began to suspect that sys. args [1] was used incorrectly in the program, and found that import numpy was the direct cause that led to the code not being packaged for a long time.

I don't know why referencing this package can't be packaged as exe normally.

The code that made the error in the program compilation is as follows


pyinstaller -F C:\Users\LHD_PC\AppData\Local\Progr
ams\Python\Python38-32\Scripts\AutoElecCalcE.py
91 INFO: PyInstaller: 3.6
91 INFO: Python: 3.8.0
93 INFO: Platform: Windows-10-10.0.17134-SP0
94 INFO: wrote C:\Users\LHD_PC\AppData\Local\Programs\Python\Python38-32\Scripts\AutoElecCalcE.spec
99 INFO: UPX is not available.
101 INFO: Extending PYTHONPATH with paths
[ ' C:\Users\LHD_PC\AppData\Local\Programs\Python\Python38-32\Scripts',
 ' C:\Users\LHD_PC\AppData\Local\Programs\Python\Python38-32\Scripts']
101 INFO: checking Analysis
113 INFO: Building because C:\Users\LHD_PC\AppData\Local\Programs\Python\Python38-32\Scripts\AutoElecCalcE.py changed
113 INFO: Initializing module dependency graph … 
119 INFO: Caching module graph hooks … 
134 INFO: Analyzing base_library.zip  … 
5521 INFO: Caching module dependency graph … 
5650 INFO: running Analysis Analysis-00.toc
5654 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by c:\users\lhd_pc\appdata\local\programs\python\python38-32\python.exe
6018 INFO: Analyzing C:\Users\LHD_PC\AppData\Local\Programs\Python\Python38-32\Scripts\AutoElecCalcE.py
6547 INFO: Processing pre-find module path hook distutils
6549 INFO: distutils: retargeting to non-venv dir  ' c:\users\lhd_pc\appdata\local\programs\python\python38-32\lib'
7356 INFO: Processing pre-find module path hook site
7357 INFO: site: retargeting to fake-dir  ' c:\users\lhd_pc\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\fake-modules'
8994 INFO: Processing pre-safe import module hook setuptools.extern.six.moves
12451 INFO: Processing module hooks … 
12451 INFO: Loading module hook  " hook-distutils.py " …  
12454 INFO: Loading module hook  " hook-encodings.py " …  
12744 INFO: Loading module hook  " hook-lib2to3.py " …  
12757 INFO: Loading module hook  " hook-numpy.core.py " …  
13540 INFO: Loading module hook  " hook-numpy.py " …  
13546 INFO: Loading module hook  " hook-pkg_resources.py " …  
15200 INFO: Processing pre-safe import module hook win32com
15767 INFO: Excluding import  ' main'
15769 INFO: Removing import of main from module pkg_resources
15769 INFO: Loading module hook  " hook-pydoc.py " …  
15782 INFO: Loading module hook  " hook-pythoncom.py " …  
16198 INFO: Loading module hook  " hook-pywintypes.py " …  
16605 INFO: Loading module hook  " hook-scipy.py " …  
16663 INFO: Loading module hook  " hook-setuptools.py " …  
18364 INFO: Loading module hook  " hook-sysconfig.py " …  
18375 INFO: Loading module hook  " hook-win32com.py " …  
c:\users\lhd_pc\appdata\local\programs\python\python38-32\lib\site-packages\win32com\client\makepy.py:369: SyntaxWarning:  " is not "  with a literal. Did you mean  " != " ?
if path is not  ' ' and not os.path.exists(path):
20023 INFO: Loading module hook  " hook-xml.dom.domreg.py " …  
20030 INFO: Loading module hook  " hook-xml.py " …  
20090 INFO: Looking for ctypes DLLs
20132 INFO: Analyzing run-time hooks  … 
20139 INFO: Including run-time hook  ' pyi_rth_multiprocessing.py'
20162 INFO: Including run-time hook  ' pyi_rth_pkgres.py'
20192 INFO: Including run-time hook  ' pyi_rth_win32comgenpy.py'
20229 INFO: Looking for dynamic libraries
21772 INFO: Looking for eggs
21772 INFO: Using Python library c:\users\lhd_pc\appdata\local\programs\python\python38-32\python38.dll
21773 INFO: Found binding redirects:
[]
21798 INFO: Warnings written to C:\Users\LHD_PC\AppData\Local\Programs\Python\Python38-32\Scripts\build\AutoElecCalcE\warn-AutoElecCalcE.txt
21932 INFO: Graph cross-reference written to C:\Users\LHD_PC\AppData\Local\Programs\Python\Python38-32\Scripts\build\AutoElecCalcE\xref-AutoElecCalcE.html
22003 INFO: checking PYZ
22017 INFO: Building because toc changed
22017 INFO: Building PYZ (ZlibArchive) C:\Users\LHD_PC\AppData\Local\Programs\Python\Python38-32\Scripts\build\AutoElecCalcE\PYZ-00.pyz
23373 INFO: Building PYZ (ZlibArchive) C:\Users\LHD_PC\AppData\Local\Programs\Python\Python38-32\Scripts\build\AutoElecCalcE\PYZ-00.pyz completed successfully.
23419 INFO: checking PKG
23427 INFO: Building because toc changed
23427 INFO: Building PKG (CArchive) PKG-00.pkg
37085 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
37098 INFO: Bootloader c:\users\lhd_pc\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\bootloader\Windows-32bit\run.exe
37098 INFO: checking EXE
37107 INFO: Rebuilding EXE-00.toc because AutoElecCalcE.exe missing
37107 INFO: Building EXE from EXE-00.toc
37111 INFO: Appending archive to EXE C:\Users\LHD_PC\AppData\Local\Programs\Python\Python38-32\Scripts\dist\AutoElecCalcE.exe
37154 INFO: Building EXE from EXE-00.toc completed successfully.

Before 1 straight suspected that the path was not handled correctly, after looking at a lot of other codes, it was no problem. I had a whim about whether a package could not be compressed normally, and then wrote a test file. After commenting the referenced package in 1 line, I found that as long as numpy was commented out, it could be compressed into exe file normally.

Supplement: Solution to failed installation of pyinstaller

pyinstaller is a good library for packaging python files into exe that does not depend on the python environment, but when using "pip install pyinstaller" in cmd, there are always many strange problems.

In the process of installing the library, I encountered the problem of reporting errors and exiting the installation after downloading.

The solution is as follows

1. Actually, 1 o'clock is not troublesome

2. First "pip install pywin32"

3. In "pip install wheel"

4. Try "pip install pyinstaller"


Related articles: