更新最新的 PySide 后 Pyinstaller 错误
Posted
技术标签:
【中文标题】更新最新的 PySide 后 Pyinstaller 错误【英文标题】:Pyinstaller error after updating latest PySide 【发布时间】:2019-04-03 09:09:34 【问题描述】:我有一个可以运行的 python(3.6.8) 和 Pyside(5.12.0) 应用程序。
以前我能够创建一个文件 exe 并且运行良好。
但将 Pyside 更新到 5.12.2 后,我无法运行 app。 有 ModuleNotFoundError: No module named 'typing'
我已经安装了打字模块(pip install typing)。 我尝试卸载 pyside(5.12.2) 并重新安装 pyside(5.12.0)
但我仍然遇到同样的错误。 这是错误。
Problem importing shibokensupport:
No module named 'typing'
Traceback (most recent call last):
File "(builtin)", line 93, in ensure_shibokensupport
File "(builtin)", line 133, in bootstrap
File "C:\Users\LS0020\AppData\Local\Temp\embedded.u2j069ui.zip\shibokensupport\signature\loader.py", line 156, in <module>
import typing
ModuleNotFoundError: No module named 'typing'
sys.path:
C:\Users\LS0020\AppData\Local\Temp\embedded.u2j069ui.zip
C:\Users\LS0020\AppData\Local\Temp\_MEI101642\base_library.zip
C:\Users\LS0020\AppData\Local\Temp\_MEI101642
Traceback (most recent call last):
File "(builtin)", line 93, in ensure_shibokensupport
File "(builtin)", line 133, in bootstrap
File "C:\Users\LS0020\AppData\Local\Temp\embedded.u2j069ui.zip\shibokensupport\signature\loader.py", line 156, in <module>
ModuleNotFoundError: No module named 'typing'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "(builtin)", line 133, in bootstrap
File "contextlib.py", line 99, in __exit__
File "(builtin)", line 102, in ensure_shibokensupport
SystemExit: -1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "(builtin)", line 147, in bootstrap
UnboundLocalError: local variable 'loader' referenced before assignment
SystemError: could not initialize part 2
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "demo.py", line 1, in <module>
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\PySide2\__init__.py", line 51, in <module>
File "site-packages\PySide2\__init__.py", line 21, in _setupQtDirectories
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
SystemError: PyEval_EvalFrameEx returned a result with an error set
[7584] Failed to execute script demo
【问题讨论】:
【参考方案1】:我在使用 cx_freeze 时遇到了完全相同的问题。在构建 cx_freeze 应用程序并运行后,我得到了错误:
Problem importing shibokensupport:
No module named 'typing'
Traceback (most recent call last):
File "(builtin)", line 93, in ensure_shibokensupport
File "(builtin)", line 133, in bootstrap
File "/tmp/embedded.mp0z2vy0.zip/shibokensupport/signature/loader.py", line 156, in <module>
import typing
我将typing
手动添加到需要包含在cx_freeze setup.py
中的包中:
# -*- coding: utf-8 -*-
import sys
from cx_Freeze import setup, Executable
options =
'build_exe':
'packages': [
'os',
'typing'
],
'excludes': [
'tkinter'
]
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
executables = [
Executable('qt_test1.py', base=base)
]
setup(
name='qt_test1',
version='0.1',
description='My GUI application!',
options=options,
executables=executables
)
这样做。它现在运行。
这意味着对于 PyInstaller 你必须这样调用它:
$ pyinstaller your_app.py --hidden-import="typing"
实际上,我不知道 PyInstaller 是否有更好的方法可以将模块显式添加到构建过程中。
【讨论】:
以上是关于更新最新的 PySide 后 Pyinstaller 错误的主要内容,如果未能解决你的问题,请参考以下文章
Pyside2:使用属性更新 QML TableView 模型
带有 Pyside2 和 Matplotlib 的 Pyinstaller 无法正常工作