【发布时间】:2019-11-13 10:15:41
【问题描述】:
我有一个使用tkinter 作为GUI 的python 程序。我的 python 项目是一个 PyCharm 项目。它被组织为 Project\main.py Project\my_class.py Project\images\favicon.ico Project\common\util\util1.py Project\common\util\util2.py Project\venv
我移动到C:\..\Desktop\Project 文件夹并运行pyinstaller --windowed main.py 的终端
如果有人想知道终端的输出是什么,那就是
62 INFO: PyInstaller: 3.5
62 INFO: Python: 3.7.5
62 INFO: Platform: Windows-10-10.0.17763-SP0
62 INFO: wrote C:\Users\User\Desktop\Project\main.spec
62 INFO: UPX is not available.
62 INFO: Extending PYTHONPATH with paths
['C:\\Users\\User\\Desktop\\Project',
'C:\\Users\\User\\Desktop\\Project']
62 INFO: checking Analysis
78 INFO: Building Analysis because Analysis-00.toc is non existent
78 INFO: Initializing module dependency graph...
78 INFO: Initializing module graph hooks...
78 INFO: Analyzing base_library.zip ...
2124 INFO: running Analysis Analysis-00.toc
2124 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by c:\users\user\appdata\local\programs\python\python37\python.exe
3900 INFO: Caching module hooks...
3900 INFO: Analyzing C:\Users\User\Desktop\Project\main.py
4306 INFO: Processing pre-find module path hook distutils
5040 INFO: Processing pre-find module path hook site
5040 INFO: site: retargeting to fake-dir 'c:\\users\\user\\appdata\\local\\programs\\python\\python37\\lib\\site-packages\\PyInstaller\\fake-modules'
5925 INFO: Processing pre-safe import module hook setuptools.extern.six.moves
7668 INFO: Loading module hooks...
7668 INFO: Loading module hook "hook-distutils.py"...
7671 INFO: Loading module hook "hook-encodings.py"...
7743 INFO: Loading module hook "hook-lib2to3.py"...
7747 INFO: Loading module hook "hook-numpy.core.py"...
7845 INFO: Loading module hook "hook-numpy.py"...
7846 INFO: Loading module hook "hook-pkg_resources.py"...
8092 INFO: Processing pre-safe import module hook win32com
Traceback (most recent call last):
File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'win32com'
8150 INFO: Processing pre-safe import module hook win32com
Traceback (most recent call last):
File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'win32com'
8327 INFO: Loading module hook "hook-pydoc.py"...
8328 INFO: Loading module hook "hook-setuptools.py"...
8742 INFO: Loading module hook "hook-sysconfig.py"...
8742 INFO: Loading module hook "hook-xml.dom.domreg.py"...
8742 INFO: Loading module hook "hook-xml.py"...
8742 INFO: Loading module hook "hook-_tkinter.py"...
9133 INFO: checking Tree
9133 INFO: Building Tree because Tree-00.toc is non existent
9148 INFO: Building Tree Tree-00.toc
9211 INFO: checking Tree
9211 INFO: Building Tree because Tree-01.toc is non existent
9211 INFO: Building Tree Tree-01.toc
9258 INFO: Looking for ctypes DLLs
9273 INFO: Analyzing run-time hooks ...
9273 INFO: Including run-time hook 'pyi_rth_pkgres.py'
9289 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
9289 INFO: Including run-time hook 'pyi_rth__tkinter.py'
9289 INFO: Looking for dynamic libraries
18180 INFO: Looking for eggs
18180 INFO: Using Python library c:\users\user\appdata\local\programs\python\python37\python37.dll
18180 INFO: Found binding redirects:
[]
18180 INFO: Warnings written to C:\Users\User\Desktop\Project\build\main\warn-main.txt
18445 INFO: Graph cross-reference written to C:\Users\User\Desktop\Project\build\main\xref-main.html
18492 INFO: checking PYZ
18492 INFO: Building PYZ because PYZ-00.toc is non existent
18492 INFO: Building PYZ (ZlibArchive) C:\Users\User\Desktop\Project\build\main\PYZ-00.pyz
19259 INFO: Building PYZ (ZlibArchive) C:\Users\User\Desktop\Project\build\main\PYZ-00.pyz completed successfully.
19274 INFO: checking PKG
19274 INFO: Building PKG because PKG-00.toc is non existent
19274 INFO: Building PKG (CArchive) PKG-00.pkg
19290 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
19290 INFO: Bootloader c:\users\user\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\bootloader\Windows-64bit\runw.exe
19290 INFO: checking EXE
19290 INFO: Building EXE because EXE-00.toc is non existent
19290 INFO: Building EXE from EXE-00.toc
19290 INFO: Appending archive to EXE C:\Users\User\Desktop\Project\build\main\main.exe
19306 INFO: Building EXE from EXE-00.toc completed successfully.
19306 INFO: checking COLLECT
19306 INFO: Building COLLECT because COLLECT-00.toc is non existent
19306 INFO: Building COLLECT COLLECT-00.toc
22581 INFO: Building COLLECT COLLECT-00.toc completed successfully.
我该如何解决这个问题?你有什么想法吗?
【问题讨论】:
-
运行不带
--windowed参数的pyinstaller。然后从控制台运行生成的 main.exe。控制台应该显示额外的错误回溯,这将帮助您识别根本问题。 -
@Xukrao 这里是错误
ModuleNotFoundError: No module named 'matplotlib' -
经常发生 pyinstaller 无法自动检测脚本使用的一些包的情况。在这种情况下,您必须通过手动指定这些“隐藏”包来帮助 pyinstaller。见Listing Hidden Imports。
-
@Xukrao 我试过了,但我不知道我是否做对了,但现在在终端上,它会打印一个
Traceback ...和ModuleNotFoundError: No module named 'win32com'。这就是“列出隐藏的导入”的意思? -
遇到
ModuleNotFoundError时,为该模块添加一个pyinstaller--hidden-import MODULENAME参数。继续这样做,直到不再出现错误为止。
标签: python python-3.x tkinter pyinstaller