Python应用程序到一个文件.exe,编译后应用程序将不会运行

2024-09-27 21:27:13 发布

您现在位置:Python中文网/ 问答频道 /正文

大家好,, 我的主要问题已经解决了,然而,我在编译时遇到的新问题,可能值得一个新的帖子。我正试图研究这个问题。到目前为止,我发现pyinstaller不做jinja2。然而,我可以从他们2018年的更新中看到,pyinstaller现在可以做到这一点。我会继续研究的,谢谢你的帮助

编辑: 你好,我找到了我出错的原因。我没有拉我的应用程序中包含的Ico文件。 但现在我遇到了新问题,我的jinja2没有进入应用程序

我确实试过: --hiddenimport“jinja2” 我也试过: --附加挂钩目录“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,到目前为止编译是成功的,但是当我尝试运行该应用程序时,我得到了致命错误,我的应用程序不会运行

请帮忙,如果需要,我会提供更多信息

起初我在想,因为我使用的是Python3.8版本,后来我降级到3.7.4,它仍然无法运行

我正在使用auto-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

我会研究这个问题,如果我找到一个解决方案,我会把它贴在这里


Tags: topyimportinfoapplocalhookusers
2条回答

更新

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

我在上面的帖子中建议,我试着包含缺失的模块。但似乎没有什么帮助,我总是在尝试编译时得到这些“信息”

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

这是另一件有趣的事情,它试图找到事件,而我的应用程序甚至没有使用它

编辑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

相关问题 更多 >

    热门问题