Python3.8环境下PySide6无法加载Shiboken DLL问题求助(Win7)
问题:PySide6在Python3.8(Windows7)中无法导入Shiboken,DLL加载失败
我编写了一个PySide6应用,打包为exe后在Windows7上运行失败。排查发现是Python版本问题——原本使用的Python3.12不支持Windows7,该系统最高仅支持Python3.8。于是我安装Python3.8并创建虚拟环境,复制项目文件后安装PySide6,运行应用时出现以下异常:
PySide6/__init__.py: Unable to import Shiboken from D:\FinanceHelper\FinanceHelper, D:\FinanceHelper\FinanceHelper, C:\Program Files\JetBrains\PyCharm2024.2\plugins\python-ce\helpers\pycharm_display, C:\Users\xeniy\AppData\Local\Programs\Python\Python38\python38.zip, C:\Users\xeniy\AppData\Local\Programs\Python\Python38\DLLs, C:\Users\xeniy\AppData\Local\Programs\Python\Python38\lib, C:\Users\xeniy\AppData\Local\Programs\Python\Python38, D:\FinanceHelper\FinanceHelper\.venv, D:\FinanceHelper\FinanceHelper\.venv\lib\site-packages, C:\Program Files\JetBrains\PyCharm2024.2\plugins\python-ce\helpers\pycharm_matplotlib_backend, C:\Program Files\JetBrains\PyCharm2024.2\plugins\python-ce\helpers\pycharm_plotly_backend Traceback (most recent call last): File "D:\FinanceHelper\FinanceHelper\main.py", line 3, in <module> from PySide6.QtWidgets import QApplication File "D:\FinanceHelper\FinanceHelper\.venv\lib\site-packages\PySide6\__init__.py", line 124, in <module> _setupQtDirectories() File "D:\FinanceHelper\FinanceHelper\.venv\lib\site-packages\PySide6\__init__.py", line 64, in _setupQtDirectories from shiboken6 import Shiboken File "D:\FinanceHelper\FinanceHelper\.venv\lib\site-packages\shiboken6\__init__.py", line 27, in <module> from shiboken6.Shiboken import * ImportError: DLL load failed while importing Shiboken: 指定的程序未找到。
shiboken6文件夹内容如下:
我已尝试重新安装库,还安装了旧版本:
pip install PySide6==6.6.3 shiboken6==6.6.3 pyside6-addons==6.6.3 pyside6-essentials==6.6.3 Collecting PySide6==6.6.3 Obtaining dependency information for PySide6==6.6.3 from https://files.pythonhosted.org/packages/c0/a2/5e70cfd298c33f9d7a658086367999306c09d99eb75b0ad2e042fdc84279/PySide6-6.6.3-cp38-abi3-win_amd64.whl.metadata Using cached PySide6-6.6.3-cp38-abi3-win_amd64.whl.metadata (5.5 kB) Collecting shiboken6==6.6.3 Obtaining dependency information for shiboken6==6.6.3 from https://files.pythonhosted.org/packages/98/06/4f409d6f241f276ac3233023de12d34367af9cfb1bab76bbbdefa8da8182/shiboken6-6.6.3-cp38-abi3-win_amd64.whl.metadata Using cached shiboken6-6.6.3-cp38-abi3-win_amd64.whl.metadata (2.6 kB) Collecting pyside6-addons==6.6.3 Obtaining dependency information for pyside6-addons==6.6.3 from https://files.pythonhosted.org/packages/e5/46/1c9e3d93c412f5f712a0c530f128346a1b9cb1e2c6d71040cf8d70a13955/PySide6_Addons-6.6.3-cp38-abi3-win_amd64.whl.metadata Using cached PySide6_Addons-6.6.3-cp38-abi3-win_amd64.whl.metadata (4.2 kB) Collecting pyside6-essentials==6.6.3 Obtaining dependency information for pyside6-essentials==6.6.3 from https://files.pythonhosted.org/packages/72/5e/84f70f643a9d4de4e302dad3906181ca6c186fed2cf432b22f04869bf290/PySide6_Essentials-6.6.3-cp38-abi3-win_amd64.whl.metadata Using cached PySide6_Essentials-6.6.3-cp38-abi3-win_amd64.whl.metadata (3.8 kB) Using cached PySide6-6.6.3-cp38-abi3-win_amd64.whl (520 kB) Using cached shiboken6-6.6.3-cp38-abi3-win_amd64.whl (1.1 MB) Using cached PySide6_Addons-6.6.3-cp38-abi3-win_amd64.whl (104.1 MB) Using cached PySide6_Essentials-6.6.3-cp38-abi3-win_amd64.whl (75.0 MB) Installing collected packages: shiboken6, pyside6-essentials, pyside6-addons, PySide6 Successfully installed PySide6-6.6.3 pyside6-addons-6.6.3 pyside6-essentials-6.6.3 shiboken6-6.6.3
但以上操作均未解决问题,求能让应用在Windows7上正常运行的解决方案。
解决方案
1. 降级到Windows7兼容的PySide6版本
Qt 6.5及后续版本已停止支持Windows7,你安装的6.6.3版本本身不兼容该系统。需降级到最后支持Windows7的6.4.x分支:
pip uninstall -y PySide6 shiboken6 pyside6-addons pyside6-essentials pip install PySide6==6.4.3 shiboken6==6.4.3 pyside6-addons==6.4.3 pyside6-essentials==6.4.3
2. 安装Windows7必备系统补丁
Windows7需安装KB2533623补丁,该补丁用于支持SHA-2签名的应用和DLL,缺失会导致无法加载新组件。
3. 检查Python3.8安装完整性
- 安装Python3.8时务必勾选
Add Python to PATH和Install for all users - 安装后重启电脑,确保环境变量生效
- 在命令行执行
python --version和pip --version,确认路径指向Python3.8的虚拟环境
4. 打包时的兼容配置
若后续用PyInstaller打包,需注意:
- 使用PyInstaller 5.x版本(6+版本不再支持Windows7)
- 打包命令添加
--hidden-import shiboken6参数,确保Shiboken被正确包含 - 手动将虚拟环境中
Lib\site-packages\shiboken6和PySide6下的DLL文件复制到打包后的目录
5. 排查缺失的依赖
用Dependency Walker工具打开shiboken6\Shiboken.pyd文件,查看具体缺失的DLL,针对性安装对应的系统组件或库。
内容的提问来源于stack exchange,提问作者Ксения Манжула
相关产品推荐
相关产品推荐

