最新消息:20210917 已从crifan.com换到crifan.org

【未解决】pyinstaller打包运行失败:failed to execute script __main__

Python crifan 18495浏览 0评论

别人参考:

【记录】用PyInstaller把Python代码打包成单个独立的exe可执行文件 – 在路上

去折腾:

用pyinstaller 打包python工程,中间没有错误也没有warning。生成exe后点击是这样的

pyinstaller failed to execute script main

Error running the exe file in Windows “Failed to execute script pyi_rth_pkgres” · Issue #2137 · pyinstaller/pyinstaller

Failed to execute script · Issue #2015 · pyinstaller/pyinstaller

“Failed to execute script pyi_rth_qt4plugins” error when import any Python Data Stack library · Issue #2461 · pyinstaller/pyinstaller

python – Windows- Pyinstaller Error “failed to execute script ” When App Clicked – Stack Overflow

pyinstaller打包运行报错failed to execute script main – CSDN博客

pyinstaller-Failed to execute script main解决 – 一路漂泊 – 博客园

其中一个是

打包时加上 –hidden-import=xxx 对应着你自己项目中可能遇到的库

另外一个是:

想办法try catch找到出错信息 然后就容易找到问题根本原因了

问:

库是要求绝对路径么?

—hides-import

后面的参数只写了module name

答:

你应该:

去找官网 看看具体的解释 然后再去使用该参数

所以就是:

去试试:

pyinstaller —help

之类的

或者去官网

找到该命令的解释

然后看懂解释 再去使用

google 搜:

pyinstaller hides-import

pyinstaller hidden-import

找到:

When Things Go Wrong — PyInstaller 3.2 documentation

搜:

hidden-import

看到:

“Listing Hidden Imports

If Analysis thinks it has found all the imports, but the app fails with an import error, the problem is a hidden import; that is, an import that is not visible to the analysis phase.

Hidden imports can occur when the code is using __import__ or perhaps exec or eval. Hidden imports can also occur when an extension module uses the Python/C API to do an import. When this occurs, Analysis can detect nothing. There will be no warnings, only an ImportError at run-time.

To find these hidden imports, build the app with the -v flag (Getting Python’s Verbose Imports above) and run it.

Once you know what modules are needed, you add the needed modules to the bundle using the –hidden-import= command option, or by editing the spec file, or with a hook file (see Understanding PyInstaller Hooks below).”

根据解释:

你最好先

运行app 加上-v参数 这样会输入 verbose 详细信息

然后可以发现是不是导入其他某些库 没有找到 而导致app运行失败

如果是,再找到是缺了哪些库

然后才是用—hidden-import=xxx 去加上这些库

你先把你运行出错的截图 和 所用的命令发我看看

需要先搞清楚 你是如何运行app 如何出错 具体什么错误

打包时的对应log:

E:\orange3-master-3.6.1\Orange\canvas>pyinstaller -F -w __main__.py
119 INFO: PyInstaller: 3.3
119 INFO: Python: 3.4.4
120 INFO: Platform: Windows-10-10.0.15063
121 INFO: wrote E:\orange3-master-3.6.1\Orange\canvas\__main__.spec
123 INFO: UPX is not available.
124 INFO: Extending PYTHONPATH with paths
[‘E:\\orange3-master-3.6.1’, ‘E:\\orange3-master-3.6.1\\Orange\\canvas’]
125 INFO: checking Analysis
125 INFO: Building Analysis because out00-Analysis.toc is non existent
125 INFO: Initializing module dependency graph…
128 INFO: Initializing module graph hooks…
144 INFO: Analyzing base_library.zip …
4371 INFO: Processing pre-find module path hook   distutils
7476 INFO: running Analysis out00-Analysis.toc
7883 INFO: Caching module hooks…
7890 INFO: Analyzing E:\orange3-master-3.6.1\Orange\canvas\__main__.py
11322 INFO: Processing pre-find module path hook   site
11336 INFO: site: retargeting to fake-dir ‘C:\\Python34\\lib\\site-packages\\pyinstaller-3.3-py3.4.egg\\PyInstaller\\fake-modules’
22525 INFO: Processing pre-find module path hook   PyQt5.uic.port_v3
22556 INFO: Processing pre-find module path hook   PyQt5.uic.port_v2
30938 INFO: Processing pre-safe import module hook   urllib3.packages.six.moves
32727 INFO: Processing pre-safe import module hook   win32com
35112 INFO: Loading module hooks…
35112 INFO: Loading module hook “hook-sysconfig.py”…
35128 INFO: Loading module hook “hook-xml.dom.domreg.py”…
35128 INFO: Loading module hook “hook-scipy.special._ufuncs.py”…
35129 INFO: Loading module hook “hook-xml.py”…
35131 INFO: Loading module hook “hook-pydoc.py”…
35135 INFO: Loading module hook “hook-PyQt5.QtPrintSupport.py”…
35857 INFO: Loading module hook “hook-encodings.py”…
35962 INFO: Loading module hook “hook-scipy.linalg.py”…
35964 INFO: Loading module hook “hook-docutils.py”…
39863 INFO: Loading module hook “hook-distutils.py”…
39876 INFO: Loading module hook “hook-PyQt5.QtWebKitWidgets.py”…
39878 INFO: Loading module hook “hook-xml.etree.cElementTree.py”…
39878 INFO: Loading module hook “hook-pkg_resources.py”…
40518 INFO: Loading module hook “hook-scipy.sparse.csgraph.py”…
40530 INFO: Loading module hook “hook-sklearn.metrics.cluster.py”…
40564 INFO: Loading module hook “hook-pygments.py”…
42739 INFO: Loading module hook “hook-PyQt5.py”…
42744 INFO: Loading module hook “hook-PyQt5.uic.py”…
42748 INFO: Loading module hook “hook-PyQt5.QtWidgets.py”…
42749 INFO: Loading module hook “hook-shelve.py”…
42770 INFO: Loading module hook “hook-lib2to3.py”…
42784 INFO: Loading module hook “hook-PyQt5.QtTest.py”…
42785 INFO: Loading module hook “hook-PyQt5.QtCore.py”…
42855 INFO: Loading module hook “hook-setuptools.py”…
42914 INFO: Loading module hook “hook-PyQt5.QtNetwork.py”…
42986 INFO: Loading module hook “hook-PyQt5.Qt.py”…
42987 INFO: Loading module hook “hook-win32com.py”…
43482 INFO: Loading module hook “hook-PyQt5.QtOpenGL.py”…
43483 INFO: Loading module hook “hook-pythoncom.py”…
43785 INFO: Loading module hook “hook-sqlite3.py”…
43954 INFO: Loading module hook “hook-pywintypes.py”…
44243 INFO: Loading module hook “hook-numpy.core.py”…
44334 INFO: Loading module hook “hook-scipy.special._ellip_harm_2.py”…
44335 INFO: Loading module hook “hook-PyQt5.QtSvg.py”…
44336 INFO: Loading module hook “hook-PyQt5.QtGui.py”…
44765 INFO: Loading module hook “hook-certifi.py”…
44768 INFO: Loading module hook “hook-PyQt5.QtWebKit.py”…
44887 INFO: checking Tree
44888 INFO: Building Tree because out00-Tree.toc is non existent
44889 INFO: Building Tree out00-Tree.toc
44907 INFO: Looking for ctypes DLLs
45069 INFO: Analyzing run-time hooks …
45086 INFO: Including run-time hook ‘pyi_rth_multiprocessing.py’
45105 INFO: Including run-time hook ‘pyi_rth_qt5.py’
45108 INFO: Including run-time hook ‘pyi_rth_win32comgenpy.py’
45110 INFO: Including run-time hook ‘pyi_rth_pkgres.py’
45144 INFO: Looking for dynamic libraries
57666 INFO: Looking for eggs
57666 INFO: Using Python library C:\Windows\system32\python34.dll
57668 INFO: Found binding redirects:
[]
57694 INFO: Warnings written to E:\orange3-master-3.6.1\Orange\canvas\build\__main__\warn__main__.txt
58107 INFO: Graph cross-reference written to E:\orange3-master-3.6.1\Orange\canvas\build\__main__\xref-__main__.html
58398 INFO: checking PYZ
58398 INFO: Building PYZ because out00-PYZ.toc is non existent
58401 INFO: Building PYZ (ZlibArchive) E:\orange3-master-3.6.1\Orange\canvas\build\__main__\out00-PYZ.pyz
64123 INFO: Building PYZ (ZlibArchive) E:\orange3-master-3.6.1\Orange\canvas\build\__main__\out00-PYZ.pyz completed successfully.
64332 INFO: checking PKG
64332 INFO: Building PKG because out00-PKG.toc is non existent
64333 INFO: Building PKG (CArchive) out00-PKG.pkg
98660 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.
98738 INFO: Bootloader C:\Python34\lib\site-packages\pyinstaller-3.3-py3.4.egg\PyInstaller\bootloader\Windows-32bit\runw.exe
98738 INFO: checking EXE
98738 INFO: Building EXE because out00-EXE.toc is non existent
98738 INFO: Building EXE from out00-EXE.toc
98738 INFO: Appending archive to EXE E:\orange3-master-3.6.1\Orange\canvas\dist\__main__.exe
98785 INFO: Building EXE from out00-EXE.toc completed successfully.

pyinstaller 3.3 manual

PyInstaller Manual — PyInstaller 3.3 documentation

Using PyInstaller — PyInstaller 3.3 documentation

Windows and Mac OS X specific options

-w, –windowed, –noconsole
 
Windows and Mac OS X: do not provide a console window for standard i/o. On Mac OS X this also triggers building an OS X .app bundle. This option is ignored in *NIX systems.

windows pyinstaller failed to execute script

转载请注明:在路上 » 【未解决】pyinstaller打包运行失败:failed to execute script __main__

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
99 queries in 0.200 seconds, using 23.46MB memory