我使用Pycharm编写.py源代码,当我在Pycharm中使用“运行”时,它可以正常工作。 完成源代码的编写后,我想使用Pyinstaller将代码打包到可执行文件中,打包过程可以正常工作并创建.exe文件。 但是当我双击可执行文件时,没有任何反应。不知道怎么了,请帮帮我。 Pyinstaller在txt文件中创建了一个警告报告,但是我不认为这是主要原因,无论如何我还是将其附加在底部。
(venv) D:\Dropbox\Project\Pycharm Projects\biaobai>pyinstaller -F -w -i aixin.ico main.py
1405 INFO: PyInstaller: 3.3.1
1411 INFO: Python: 3.7.0
1413 INFO: Platform: Windows-10-10.0.17134-SP0
1418 INFO: wrote D:\Dropbox\Project\Pycharm Projects\biaobai\main.spec
1431 INFO: UPX is not available.
1448 INFO: Extending PYTHONPATH with paths
['D:\\Dropbox\\Project\\Pycharm Projects\\biaobai',
'D:\\Dropbox\\Project\\Pycharm Projects\\biaobai']
1449 INFO: checking Analysis
1449 INFO: Building Analysis because out00-Analysis.toc is non existent
1450 INFO: Initializing module dependency graph...
1455 INFO: Initializing module graph hooks...
1458 INFO: Analyzing base_library.zip ...
6290 INFO: running Analysis out00-Analysis.toc
6321 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by D:\Dropbox\Project\Pycharm Projects\biaobai\venv\Scripts\python.exe
8194 INFO: Caching module hooks...
8206 INFO: Analyzing D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
9513 INFO: Loading module hooks...
9513 INFO: Loading module hook "hook-encodings.py"...
9628 INFO: Loading module hook "hook-PIL.Image.py"...
10335 INFO: Processing pre-find module path hook distutils
10591 INFO: Loading module hook "hook-PIL.py"...
10607 INFO: Excluding import 'PySide'
10609 INFO: Removing import of PySide from module PIL.ImageQt
10611 INFO: Import to be excluded not found: 'FixTk'
10612 INFO: Excluding import 'tkinter'
10614 INFO: Removing import of tkinter from module PIL.ImageTk
10615 INFO: Excluding import 'PyQt4'
10618 INFO: Removing import of PyQt4 from module PIL.ImageQt
10619 INFO: Excluding import 'PyQt5'
10620 INFO: Removing import of PyQt5 from module PIL.ImageQt
10621 INFO: Loading module hook "hook-PIL.SpiderImagePlugin.py"...
10651 INFO: Import to be excluded not found: 'FixTk'
10651 INFO: Excluding import 'tkinter'
10652 INFO: Loading module hook "hook-pydoc.py"...
10657 INFO: Loading module hook "hook-xml.py"...
11028 INFO: Loading module hook "hook-_tkinter.py"...
11438 INFO: checking Tree
11438 INFO: Building Tree because out00-Tree.toc is non existent
11439 INFO: Building Tree out00-Tree.toc
11549 INFO: checking Tree
11550 INFO: Building Tree because out01-Tree.toc is non existent
11550 INFO: Building Tree out01-Tree.toc
11566 INFO: Loading module hook "hook-distutils.py"...
11609 INFO: Looking for ctypes DLLs
11609 INFO: Analyzing run-time hooks ...
11613 INFO: Including run-time hook 'pyi_rth__tkinter.py'
11624 INFO: Looking for dynamic libraries
13929 INFO: Looking for eggs
13929 INFO: Using Python library D:\Dropbox\Project\Pycharm Projects\biaobai\venv\Scripts\python37.dll
13930 INFO: Found binding redirects:
[]
13934 INFO: Warnings written to D:\Dropbox\Project\Pycharm Projects\biaobai\build\main\warnmain.txt
14026 INFO: Graph cross-reference written to D:\Dropbox\Project\Pycharm Projects\biaobai\build\main\xref-main.html
14105 INFO: checking PYZ
14105 INFO: Building PYZ because out00-PYZ.toc is non existent
14105 INFO: Building PYZ (ZlibArchive) D:\Dropbox\Project\Pycharm Projects\biaobai\build\main\out00-PYZ.pyz
15080 INFO: Building PYZ (ZlibArchive) D:\Dropbox\Project\Pycharm Projects\biaobai\build\main\out00-PYZ.pyz completed successfully.
15095 INFO: checking PKG
15095 INFO: Building PKG because out00-PKG.toc is non existent
15096 INFO: Building PKG (CArchive) out00-PKG.pkg
18477 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.
18528 INFO: Bootloader D:\Dropbox\Project\Pycharm Projects\biaobai\venv\lib\site-packages\PyInstaller\bootloader\Windows-32bit\runw.exe
18529 INFO: checking EXE
18529 INFO: Building EXE because out00-EXE.toc is non existent
18530 INFO: Building EXE from out00-EXE.toc
18555 INFO: SRCPATH [('aixin.ico', None)]
18555 INFO: Updating icons from ['aixin.ico'] to C:\Users\ADMINI~1\AppData\Local\Temp\tmp14uu9lyu
18556 INFO: Writing RT_GROUP_ICON 0 resource with 20 bytes
18556 INFO: Writing RT_ICON 1 resource with 28840 bytes
18566 INFO: Appending archive to EXE D:\Dropbox\Project\Pycharm Projects\biaobai\dist\main.exe
18591 INFO: Building EXE from out00-EXE.toc completed successfully.
warnmain.txt:
missing module named resource - imported by posix, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named posix - imported by os, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named _posixsubprocess - imported by subprocess, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named org - imported by pickle, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named readline - imported by cmd, code, pdb, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
excluded module named _frozen_importlib - imported by importlib, importlib.abc, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named _frozen_importlib_external - imported by importlib._bootstrap, importlib, importlib.abc, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named _winreg - imported by platform, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named _scproxy - imported by urllib.request
missing module named java - imported by platform, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named 'java.lang' - imported by platform, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py, xml.sax._exceptions
missing module named vms_lib - imported by platform, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named termios - imported by tty, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py, getpass
missing module named grp - imported by shutil, tarfile, pathlib, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py
missing module named pwd - imported by posixpath, shutil, tarfile, http.server, webbrowser, pathlib, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py, netrc, getpass
missing module named 'org.python' - imported by copy, D:\Dropbox\Project\Pycharm Projects\biaobai\main.py, xml.sax
missing module named cffi - imported by PIL.Image, PIL.PyAccess, PIL.ImageTk
missing module named Tkinter - imported by PIL.ImageTk
missing module named olefile - imported by PIL.FpxImagePlugin, PIL.MicImagePlugin
missing module named UserDict - imported by PIL.PdfParser
missing module named 'PySide.QtCore' - imported by PIL.ImageQt
missing module named 'PyQt4.QtCore' - imported by PIL.ImageQt
missing module named 'PyQt5.QtCore' - imported by PIL.ImageQt
missing module named numpy - imported by PIL.ImageFilter
missing module named pathlib2 - imported by PIL.Image
missing module named __builtin__ - imported by PIL.Image
答案 0 :(得分:0)
发生的事情是,Pyinstaller未能找到您在脚本中使用的某些模块的路径。要解决此问题,最简单的方法是扩展路径。您可以在pycharm终端中运行此命令,以将这些路径添加到specs文件中。或者,您可以编辑specs文件本身。
pyi-makespec --paths=/path/to/thisdir \
--paths=/path/to/otherdir myscript.py
包括脚本可能正在搜索导入的所有其他位置。这些路径将在分析期间添加到 sys.path 。
如果这对您不起作用,请尝试隐藏导入,扩展包路径并添加运行时挂钩,如here所示。
答案 1 :(得分:0)
我尝试通过“ pyinstaller -F main.py”打包可执行文件,而不是使用“ pyinstaller -F -w main.py”打包。这使我能够通过CMD运行窗口应用程序,然后出现以下错误:
致命的Python错误:Py_Initialize:无法获取语言环境编码
zipimport.ZipImportError:找不到当前模块“编码”
线程0x00003d20(最近调用优先):
通过搜索以上错误消息,我认为我得到了答案:[zipimport.ZipImportError: can't find module 'encodings' 结论应该是: Pyinstaller 3.3.1不支持Python 3.7 。
现在,我尝试将Python版本从3.7更改为3.6.3,打包工作正常,最后,我能够正常运行.exe文件。