文章目录前言一、PyQt6引用后报错二、使用步骤总结前言想做个好看的界面引用了PyQt6却产生了新问题。pip install pyqt6-tools优先做这个动作进行修复。一、PyQt6引用后报错python里引用fromPyQt6.QtWidgetsimport(QApplication,QMainWindow,QWidget,QVBoxLayout,QHBoxLayout,QPushButton,QLabel,QLineEdit,QTextEdit,QComboBox,QSpinBox,QDoubleSpinBox,QFileDialog,QScrollArea,QFrame,QSplitter,QTabWidget,QGroupBox,QCheckBox,QSlider,QStatusBar,QSizeGrip,QStackedWidget,QPlainTextEdit,QProgressBar,QMessageBox)fromPyQt6.QtCoreimport(Qt,QThread,pyqtSignal,QTimer,QSize,QPoint,QRect,QPropertyAnimation,QEasingCurve)fromPyQt6.QtGuiimport(QFont,QColor,QPalette,QIcon,QPixmap,QPainter,QLinearGradient,QBrush,QPen,QTextCursor,QAction,QFontMetrics)运行后报错from PyQt6.QtWidgetsimport(ImportError: DLL load failedwhileimporting QtWidgets: 找不到指定的程序。二、使用步骤这是一个非常典型的 Python 环境配置问题。报错 ImportError: DLL load failed while importing QtWidgets: 找不到指定的程序说明你的 Python 环境在尝试加载 PyQt6 的图形界面组件时找不到其依赖的底层动态链接库DLL文件。这通常不是代码写错了而是环境或依赖包出现了问题。你可以按照以下步骤逐一排查解决彻底重装 PyQt6 依赖包最常见的情况是 PyQt6 安装不完整或者与你当前的 Python 版本不兼容。先卸载现有版本pip uninstall PyQt6 PyQt6-Qt6 PyQt6-sip-y重新安装最新版本关键pyqt6-tools也要安装pipinstallPyQt6 pipinstallpyqt6-tools运行结果如下(base)C:\Users\onepipinstallPyQt6 Collecting PyQt6 Using cached pyqt6-6.11.0-cp310-abi3-win_amd64.whl.metadata(2.2kB)Collecting PyQt6-sip14,13.8(from PyQt6)Using cached pyqt6_sip-13.11.1-cp311-cp311-win_amd64.whl.metadata(516bytes)Collecting PyQt6-Qt66.12.0,6.11.0(from PyQt6)Using cached pyqt6_qt6-6.11.1-py3-none-win_amd64.whl.metadata(552bytes)Using cached pyqt6-6.11.0-cp310-abi3-win_amd64.whl(6.8MB)Using cached pyqt6_qt6-6.11.1-py3-none-win_amd64.whl(78.4MB)Using cached pyqt6_sip-13.11.1-cp311-cp311-win_amd64.whl(54kB)Installing collected packages: PyQt6-Qt6, PyQt6-sip, PyQt6 Successfully installed PyQt6-6.11.0 PyQt6-Qt6-6.11.1 PyQt6-sip-13.11.1(base)C:\Users\onepipinstallpyqt6-tools Collecting pyqt6-tools Downloading pyqt6_tools-6.4.2.3.3-py3-none-any.whl.metadata(8.3kB)Requirement already satisfied: clickinD:\ProgramData\anaconda3\Lib\site-packages(from pyqt6-tools)(8.3.3)Collectingpyqt66.4.2(from pyqt6-tools)Downloading PyQt6-6.4.2-cp37-abi3-win_amd64.whl.metadata(2.2kB)Collecting pyqt6-plugins6.4.2.3,6.4.2.2.2(from pyqt6-tools)Downloading pyqt6_plugins-6.4.2.2.3-cp311-cp311-win_amd64.whl.metadata(2.0kB)Requirement already satisfied: python-dotenvinD:\ProgramData\anaconda3\Lib\site-packages(from pyqt6-tools)(0.21.0)Requirement already satisfied: PyQt6-sip14,13.4inD:\ProgramData\anaconda3\Lib\site-packages(frompyqt66.4.2-pyqt6-tools)(13.11.1)Requirement already satisfied: PyQt6-Qt66.4.0inD:\ProgramData\anaconda3\Lib\site-packages(frompyqt66.4.2-pyqt6-tools)(6.11.1)Collecting PyQt6-Qt66.4.0(frompyqt66.4.2-pyqt6-tools)Downloading PyQt6_Qt6-6.4.3-py3-none-win_amd64.whl.metadata(551bytes)Collecting qt6-tools6.4.3.2,6.4.3.1.2(from pyqt6-plugins6.4.2.3,6.4.2.2.2-pyqt6-tools)Downloading qt6_tools-6.4.3.1.3-py3-none-any.whl.metadata(1.9kB)Collecting qt6-applications6.4.3.3,6.4.3.2.2(from qt6-tools6.4.3.2,6.4.3.1.2-pyqt6-plugins6.4.2.3,6.4.2.2.2-pyqt6-tools)Downloading qt6_applications-6.4.3.2.3-py3-none-win_amd64.whl.metadata(2.2kB)Requirement already satisfied: coloramainD:\ProgramData\anaconda3\Lib\site-packages(from click-pyqt6-tools)(0.4.6)Downloading pyqt6_tools-6.4.2.3.3-py3-none-any.whl(29kB)Downloading PyQt6-6.4.2-cp37-abi3-win_amd64.whl(6.4MB)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━6.4/6.4 MB3.3MB/s0:00:02 Downloading pyqt6_plugins-6.4.2.2.3-cp311-cp311-win_amd64.whl(72kB)Downloading PyQt6_Qt6-6.4.3-py3-none-win_amd64.whl(57.5MB)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━57.5/57.5 MB3.7MB/s0:00:15 Downloading qt6_tools-6.4.3.1.3-py3-none-any.whl(13kB)Downloading qt6_applications-6.4.3.2.3-py3-none-win_amd64.whl(71.3MB)━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━71.3/71.3 MB8.5MB/s0:00:08 Installing collected packages: PyQt6-Qt6, qt6-applications, pyqt6, qt6-tools, pyqt6-plugins, pyqt6-tools Attempting uninstall: PyQt6-Qt6 Found existing installation: PyQt6-Qt66.11.1 Uninstalling PyQt6-Qt6-6.11.1: Successfully uninstalled PyQt6-Qt6-6.11.1 Attempting uninstall: pyqt6 Found existing installation: PyQt66.11.0 Uninstalling PyQt6-6.11.0: Successfully uninstalled PyQt6-6.11.0 Successfully installed PyQt6-Qt6-6.4.3 pyqt6-6.4.2 pyqt6-plugins-6.4.2.2.3 pyqt6-tools-6.4.2.3.3 qt6-applications-6.4.3.2.3 qt6-tools-6.4.3.1.3总结我python 3.11 重新安装后搞定。