Python应用到一个文件.exe,编译应用后将无法运行

问题描述 投票:1回答:2

你好,再次编辑,我的主要问题已经解决,但是,在编译时我遇到了新问题,可能应该再发表一篇新文章。我正在尝试研究此问题。到目前为止,我发现pyinstaller不能执行jinja2。但是,我可以从2018年的更新中看到pyinstaller现在可以做到这一点。我将继续研究,感谢您的帮助。

编辑:您好,我发现了我的错误的原因。我没有提取应用程序中包含的Ico文件。但是现在我遇到了新问题,我的jinja2没有进入应用程序。

我确实尝试过:--hiddenimport“ jinja2”我也尝试过:--additional-hooks-dir“ C:/ Users / bk / Desktop / app / venv / Lib / site-packages / jinja2”

Executing: pyinstaller --noconfirm --onefile --noconsole --icon C:/Users/bk/Desktop/Source H/logo.ico C:/Users/bk/Desktop/Source H/app.py --distpath C:\Users\bk\AppData\Local\Temp\tmphyctj9hl\application --workpath C:\Users\bk\AppData\Local\Temp\tmphyctj9hl\build --specpath C:\Users\bk\AppData\Local\Temp\tmphyctj9hl

88139 INFO: PyInstaller: 3.6
88142 INFO: Python: 3.7.4
88147 INFO: Platform: Windows-10-10.0.17763-SP0
88154 INFO: wrote C:\Users\bk\AppData\Local\Temp\tmphyctj9hl\app.spec
88161 INFO: UPX is not available.
88171 INFO: Extending PYTHONPATH with paths
['C:\\Users\\bk\\Desktop\\Source H',
 'C:\\Users\\bk\\AppData\\Local\\Temp\\tmphyctj9hl']
88175 INFO: checking Analysis
88178 INFO: Building Analysis because Analysis-00.toc is non existent
88186 INFO: Initializing module dependency graph...
88192 INFO: Caching module graph hooks...
88205 INFO: Analyzing base_library.zip ...
91478 INFO: Caching module dependency graph...
91608 INFO: running Analysis Analysis-00.toc
91644 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\users\bk\appdata\local\programs\python\python37\python.exe
91853 INFO: Analyzing C:\Users\bk\Desktop\Source H\app.py
92968 INFO: Processing pre-find module path hook   distutils
92984 INFO: distutils: retargeting to non-venv dir 'c:\\users\\bk\\appdata\\local\\programs\\python\\python37\\lib'
99328 INFO: Processing pre-find module path hook   site
99348 INFO: site: retargeting to fake-dir 'c:\\users\\bk\\appdata\\local\\programs\\python\\python37\\lib\\site-packages\\PyInstaller\\fake-modules'
101088 INFO: Processing pre-safe import module hook   setuptools.extern.six.moves
109239 INFO: Processing pre-safe import module hook   six.moves
116423 INFO: Processing pre-safe import module hook   urllib3.packages.six.moves
118005 INFO: Processing module hooks...
118009 INFO: Loading module hook "hook-certifi.py"...
118027 INFO: Loading module hook "hook-distutils.py"...
118050 INFO: Loading module hook "hook-encodings.py"...
118205 INFO: Loading module hook "hook-gevent.py"...
118943 INFO: Determining a mapping of distributions to packages...
123570 WARNING: Unable to find package for requirement greenlet from package gevent.
123573 INFO: Packages required by gevent:
['cffi']
126368 INFO: Loading module hook "hook-jinja2.py"...
126422 INFO: Loading module hook "hook-lib2to3.py"...
126448 INFO: Loading module hook "hook-lxml.etree.py"...
126466 INFO: Loading module hook "hook-numpy.core.py"...
126648 INFO: Loading module hook "hook-numpy.py"...
126665 INFO: Loading module hook "hook-pandas.py"...
128033 INFO: Loading module hook "hook-PIL.Image.py"...
128823 INFO: Loading module hook "hook-PIL.py"...
128841 INFO: Excluding import 'tkinter'
128850 INFO:   Removing import of tkinter from module PIL.ImageTk
128853 INFO: Excluding import 'PyQt5'
128858 INFO:   Removing import of PyQt5 from module PIL.ImageQt
128862 INFO: Excluding import 'PyQt4'
128871 INFO: Import to be excluded not found: 'FixTk'
128876 INFO: Import to be excluded not found: 'PySide'
128880 INFO: Loading module hook "hook-PIL.SpiderImagePlugin.py"...
128897 INFO: Excluding import 'tkinter'
128903 INFO: Import to be excluded not found: 'FixTk'
128906 INFO: Loading module hook "hook-pkg_resources.py"...
129310 INFO: Processing pre-safe import module hook   win32com
129405 INFO: Processing pre-safe import module hook   win32com
129659 INFO: Excluding import '__main__'
129667 INFO:   Removing import of __main__ from module pkg_resources
129673 INFO: Loading module hook "hook-pycparser.py"...
129690 INFO: Loading module hook "hook-pydoc.py"...
129705 INFO: Loading module hook "hook-pytz.py"...
129858 INFO: Loading module hook "hook-setuptools.py"...
130514 INFO: Loading module hook "hook-sqlite3.py"...
130693 INFO: Loading module hook "hook-sysconfig.py"...
130709 INFO: Loading module hook "hook-ttkthemes.py"...
131438 INFO: Loading module hook "hook-xml.dom.domreg.py"...
131457 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
131473 INFO: Loading module hook "hook-xml.py"...
131489 INFO: Loading module hook "hook-_tkinter.py"...
131780 INFO: checking Tree
131784 INFO: Building Tree because Tree-00.toc is non existent
131791 INFO: Building Tree Tree-00.toc
132037 INFO: checking Tree
132043 INFO: Building Tree because Tree-01.toc is non existent
132050 INFO: Building Tree Tree-01.toc
132150 INFO: Looking for ctypes DLLs
132223 INFO: Analyzing run-time hooks ...
132235 INFO: Including run-time hook 'pyi_rth_certifi.py'
132253 INFO: Including run-time hook 'pyi_rth_pkgres.py'
132272 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
132289 INFO: Including run-time hook 'pyi_rth__tkinter.py'
132324 INFO: Looking for dynamic libraries
134254 INFO: Looking for eggs
134258 INFO: Using Python library c:\users\bk\appdata\local\programs\python\python37\python37.dll
134267 INFO: Found binding redirects: 
[]
134295 INFO: Warnings written to C:\Users\bk\AppData\Local\Temp\tmphyctj9hl\build\app\warn-app.txt
134488 INFO: Graph cross-reference written to C:\Users\bk\AppData\Local\Temp\tmphyctj9hl\build\app\xref-app.html
134710 INFO: checking PYZ
134715 INFO: Building PYZ because PYZ-00.toc is non existent
134722 INFO: Building PYZ (ZlibArchive) C:\Users\bk250256\AppData\Local\Temp\tmphyctj9hl\build\app\PYZ-00.pyz
136460 INFO: Building PYZ (ZlibArchive) C:\Users\bk\AppData\Local\Temp\tmphyctj9hl\build\app\PYZ-00.pyz completed successfully.
136507 INFO: checking PKG
136510 INFO: Building PKG because PKG-00.toc is non existent
136516 INFO: Building PKG (CArchive) PKG-00.pkg
166136 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
166266 INFO: Bootloader c:\users\bk\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\bootloader\Windows-64bit\runw.exe
166273 INFO: checking EXE
166278 INFO: Building EXE because EXE-00.toc is non existent
166287 INFO: Building EXE from EXE-00.toc
166339 INFO: Copying icons from ['C:\\Users\\bk\\Desktop\\Source H\\logo.ico']
166347 INFO: Writing RT_GROUP_ICON 0 resource with 20 bytes
166353 INFO: Writing RT_ICON 1 resource with 133960 bytes
166372 INFO: Updating manifest in C:\Users\bk\AppData\Local\Temp\tmphyctj9hl\build\app\runw.exe.85edix34
166378 INFO: Updating resource type 24 name 1 language 0
166396 INFO: Appending archive to EXE C:\Users\bk\AppData\Local\Temp\tmphyctj9hl\application\app.exe
166435 INFO: Building EXE from EXE-00.toc completed successfully.

Moving project to: C:\Users\bk\output
Complete.

大家好,请帮助我,

我正在尝试将python应用程序编译为一个文件exe,到目前为止,编译成功,但是当我尝试运行该应用程序时出现致命错误,我的应用程序将无法运行。

[请帮助,如有需要,我会提供更多信息。

起初我在想,因为我使用的是python 3.8版本,然后我降级到3.7.4,但它仍然无法运行。

我使用的是自动py-to-exe,起初我确实尝试过使用py2exe,但我认为它不支持3.4版以上的python。

编辑:

当我编译为一个文件夹而不是一个文件时:

我的应用仍然无法再次运行以下弹出窗口:

enter image description here

更新:我决定尝试使用“ console on”选项进行编译,以查看导致我的程序无法运行的原因,然后通过CMD发出此错误。

Microsoft Windows [版本10.0.17763.1132](c)2018年微软公司。保留所有权利。

C:\Users\bk>auto-py-to-exe
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'win32com'
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'win32com'

C:\Users\bk>

编辑,新更新:

使用--debug运行后,

我遇到此错误:

enter image description here

如果找到解决方案,我将对此问题进行研究,并将其发布在此处。

python compilation jinja2 exe
2个回答
0
投票

编辑filename.spec并将缺少的模块添加到隐藏导入中。示例:

# -*- mode: python ; coding: utf-8 -*-

block_cipher = None

a = Analysis(['test.py'],
             pathex=['D:\\desktop\\finalfinalshort'],
             binaries=[],
             datas=[],
             hiddenimports=['winreg','win32gui','win32con'], #this are sample imports
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='test',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=False )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               upx_exclude=[],
               name='test')

然后尝试pyinstaller filename.spec。那应该工作。另外,使用pip install pywin32安装win32com。


0
投票

更新,

130319 INFO: Excluding import 'PyQt4'
130326 INFO: Excluding import 'tkinter'
130334 INFO:   Removing import of tkinter from module PIL.ImageTk
130338 INFO: Import to be excluded not found: 'FixTk'
130342 INFO: Import to be excluded not found: 'PySide'
130345 INFO: Excluding import 'PyQt5'
130351 INFO:   Removing import of PyQt5 from module PIL.ImageQt
130356 INFO: Loading module hook "hook-PIL.SpiderImagePlugin.py"...
130364 INFO: Excluding import 'tkinter'
130375 INFO: Import to be excluded not found: 'FixTk'
130378 INFO: Loading module hook "hook-pkg_resources.py"...
130942 INFO: Processing pre-safe import module hook   win32com

我在以上文章中建议我尝试包括缺少的模块。但是似乎没有什么帮助,在尝试编译时,我总是会得到此“ INFO”。

126021 WARNING: Unable to find package for requirement greenlet from package gevent.
126025 INFO: Packages required by gevent:
['cffi']

这是另一件事,它正在尝试查找事件,而我的应用甚至没有使用它。

© www.soinside.com 2019 - 2024. All rights reserved.