我正在使用 pyinstaller 在 Windows 上创建 exe 文件。我创建了基于 anaconda 的虚拟环境“py38”,并在其中安装了所有软件包。我正在尝试转换一个 tkinter 文件,即“gui.py”。当我使用正常运行时
python gui.py
命令,它工作得很好。但是使用 pyinstaller 似乎找不到我使用以下两个命令安装的模块“桨”。
python -m pip download paddlepaddle==2.1.2 -f https://www.paddlepaddle.org.cn/whl/windows/mkl/noavx/stable.html --no-index --no-deps
python -m pip install [name].whl
我一直在使用 python 3.8。我已经使用了几乎所有可以在线解决此问题的可能解决方案。
我尝试过的命令来修复它
pyinstaller --paths 'C:\\Users\\user\\anaconda3\\envs\\py38\\lib\\site-packages' --onefile --clean gui.py
pyinstaller --paths 'C:\\Users\\user\\anaconda3\\envs\\py38\\lib\\site-packages' --onedir gui.py
pyinstaller --hidden-import 'paddle' --onefile --clean gui.py
pyinstaller --hidden-import 'paddlepaddle' --onefile --clean gui.py
pyinstaller --hidden-import 'paddlepaddle' --onedir --clean gui.py
当我使用--onedir
时,生成的 exe 文件也会在启动后立即关闭。下面给出了完整的日志,当我运行指定了“--paths”的pyinstaller时
>pyinstaller --paths 'C:\\Users\\user\\anaconda3\\envs\\py38\\lib\\site-packages' --onefile --clean gui.py
586 INFO: PyInstaller: 4.5.1
587 INFO: Python: 3.8.11 (conda)
605 INFO: Platform: Windows-10-10.0.19041-SP0
610 INFO: wrote C:\Users\user\Downloads\recognizer\gui.spec
614 INFO: UPX is not available.
615 INFO: Removing temporary files and cleaning cache in C:\Users\user\AppData\Local\pyinstaller
631 INFO: Extending PYTHONPATH with paths
['C:\\Users\\user\\Downloads\\recognizer',
"C:\\Users\\user\\Downloads\\recognizer\\'C:\\Users\\user\\anaconda3\\envs\\py38\\lib\\site-packages'",
'C:\\Users\\user\\Downloads\\recognizer']
1560 INFO: checking Analysis
1561 INFO: Building Analysis because Analysis-00.toc is non existent
1561 INFO: Initializing module dependency graph...
1569 INFO: Caching module graph hooks...
1620 INFO: Analyzing base_library.zip ...
8791 INFO: Processing pre-find module path hook distutils from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
8794 INFO: distutils: retargeting to non-venv dir 'c:\\users\\user\\anaconda3\\envs\\py38\\lib'
16752 INFO: Caching module dependency graph...
17497 INFO: running Analysis Analysis-00.toc
17507 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by c:\users\user\anaconda3\envs\py38\python.exe
18231 INFO: Analyzing C:\Users\user\Downloads\recognizer\gui.py
22037 INFO: Processing pre-find module path hook site from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-site.py'.
22042 INFO: site: retargeting to fake-dir 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\fake-modules'
33819 INFO: Processing module hooks...
33822 INFO: Loading module hook 'hook-cv2.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
33832 INFO: Loading module hook 'hook-difflib.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
33837 INFO: Loading module hook 'hook-distutils.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
33839 INFO: Loading module hook 'hook-distutils.util.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
33845 INFO: Loading module hook 'hook-encodings.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
34078 INFO: Loading module hook 'hook-heapq.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
34089 INFO: Loading module hook 'hook-lib2to3.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
34191 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
34196 INFO: Loading module hook 'hook-numpy.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
34318 WARNING: Conda distribution 'numpy', dependency of 'numpy', was not found. If you installed this distribution with pip then you may ignore this warning.
34432 INFO: Import to be excluded not found: 'f2py'
34508 INFO: Loading module hook 'hook-numpy._pytesttester.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
34514 INFO: Loading module hook 'hook-pickle.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
34519 INFO: Loading module hook 'hook-PIL.Image.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
35422 INFO: Loading module hook 'hook-PIL.ImageFilter.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
35428 INFO: Loading module hook 'hook-PIL.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
35464 INFO: Loading module hook 'hook-PIL.SpiderImagePlugin.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
35470 INFO: Loading module hook 'hook-pkg_resources.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
37159 INFO: Processing pre-safe import module hook win32com from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\pre_safe_import_module\\hook-win32com.py'.
37315 WARNING: Hidden import "pkg_resources.py2_warn" not found!
37317 WARNING: Hidden import "pkg_resources.markers" not found!
37322 INFO: Loading module hook 'hook-PyQt5.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
37926 WARNING: Hidden import "sip" not found!
37931 INFO: Loading module hook 'hook-PyQt5.QtCore.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
38168 INFO: Loading module hook 'hook-PyQt5.QtGui.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
38743 INFO: Loading module hook 'hook-scipy.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
38756 INFO: Loading module hook 'hook-setuptools.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
40669 INFO: Loading module hook 'hook-sysconfig.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
40673 INFO: Loading module hook 'hook-win32ctypes.core.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
41174 INFO: Loading module hook 'hook-xml.dom.domreg.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
41177 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
41179 INFO: Loading module hook 'hook-xml.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
41180 INFO: Loading module hook 'hook-_tkinter.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
41557 INFO: checking Tree
41557 INFO: Building Tree because Tree-00.toc is non existent
41561 INFO: Building Tree Tree-00.toc
41752 INFO: checking Tree
41756 INFO: Building Tree because Tree-01.toc is non existent
41757 INFO: Building Tree Tree-01.toc
42025 INFO: checking Tree
42030 INFO: Building Tree because Tree-02.toc is non existent
42031 INFO: Building Tree Tree-02.toc
42048 INFO: Loading module hook 'hook-setuptools.msvc.py' from 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks'...
42153 INFO: Looking for ctypes DLLs
42340 INFO: Analyzing run-time hooks ...
42354 INFO: Including run-time hook 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgutil.py'
42366 INFO: Including run-time hook 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
42374 INFO: Including run-time hook 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py'
42379 INFO: Including run-time hook 'c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth__tkinter.py'
42417 INFO: Looking for dynamic libraries
43704 INFO: Looking for eggs
43706 INFO: Using Python library c:\users\user\anaconda3\envs\py38\python38.dll
43708 INFO: Found binding redirects:
[]
43723 INFO: Warnings written to C:\Users\user\Downloads\recognizer\build\gui\warn-gui.txt
44000 INFO: Graph cross-reference written to C:\Users\user\Downloads\recognizer\build\gui\xref-gui.html
44146 INFO: checking PYZ
44149 INFO: Building PYZ because PYZ-00.toc is non existent
44150 INFO: Building PYZ (ZlibArchive) C:\Users\user\Downloads\recognizer\build\gui\PYZ-00.pyz
46686 INFO: Building PYZ (ZlibArchive) C:\Users\user\Downloads\recognizer\build\gui\PYZ-00.pyz completed successfully.
46773 INFO: checking PKG
46775 INFO: Building PKG because PKG-00.toc is non existent
46777 INFO: Building PKG (CArchive) PKG-00.pkg
92228 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
92319 INFO: Bootloader c:\users\user\anaconda3\envs\py38\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
92321 INFO: checking EXE
92321 INFO: Building EXE because EXE-00.toc is non existent
92322 INFO: Building EXE from EXE-00.toc
92326 INFO: Copying icons from ['c:\\users\\user\\anaconda3\\envs\\py38\\lib\\site-packages\\PyInstaller\\bootloader\\images\\icon-console.ico']
92461 INFO: Writing RT_GROUP_ICON 0 resource with 104 bytes
92461 INFO: Writing RT_ICON 1 resource with 3752 bytes
92462 INFO: Writing RT_ICON 2 resource with 2216 bytes
92462 INFO: Writing RT_ICON 3 resource with 1384 bytes
92462 INFO: Writing RT_ICON 4 resource with 37019 bytes
92462 INFO: Writing RT_ICON 5 resource with 9640 bytes
92462 INFO: Writing RT_ICON 6 resource with 4264 bytes
92462 INFO: Writing RT_ICON 7 resource with 1128 bytes
92510 INFO: Updating manifest in C:\Users\user\Downloads\recognizer\build\gui\run.exe.s5i_qt6_
92651 INFO: Updating resource type 24 name 1 language 0
92656 INFO: Appending archive to EXE C:\Users\user\Downloads\recognizer\dist\gui.exe
139969 INFO: Building EXE from EXE-00.toc completed successfully.
(py38) C:\Users\user\Downloads\recognizer>
我还创建了两次全新的 conda 环境,并重新安装了所有软件包,即使这样也没有解决问题。
如果有人可以帮助我,那将不胜感激