Chromebook Linux环境下PyQt6安装失败求助
问题背景
在Chromebook自带的Linux桌面环境中尝试安装PyQt6,已将Python更新至3.9.2、pip更新至22.1.2,执行多种pip安装命令均失败,报错核心为sipbuild.pyproject.PyProjectOptionException及sipbuild.api属性缺失错误。
已尝试的安装命令
pip install pyqt6 pip3 install pyqt6 python -m pip install pyqt6 python3 -m pip install pyqt6
完整错误日志
Defaulting to user installation because normal site-packages is not writeable
Collecting pyqt6
Using cached PyQt6-6.3.1.tar.gz (1.0 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... error
error: subprocess-exited-with-error× Preparing metadata (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [29 lines of output]
Traceback (most recent call last):
File "/home/user1/.local/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 156, in prepare_metadata_for_build_wheel
hook = backend.prepare_metadata_for_build_wheel
AttributeError: module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel'During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/user1/.local/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module> main() File "/home/user1/.local/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main json_out['return_val'] = hook(**hook_input['kwargs']) File "/home/user1/.local/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 160, in prepare_metadata_for_build_wheel whl_basename = backend.build_wheel(metadata_directory, config_settings) File "/tmp/pip-build-env-lb2ttoa7/overlay/lib/python3.9/site-packages/sipbuild/api.py", line 46, in build_wheel project = AbstractProject.bootstrap('wheel', File "/tmp/pip-build-env-lb2ttoa7/overlay/lib/python3.9/site-packages/sipbuild/abstract_project.py", line 87, in bootstrap project.setup(pyproject, tool, tool_description) File "/tmp/pip-build-env-lb2ttoa7/overlay/lib/python3.9/site-packages/sipbuild/project.py", line 584, in setup self.apply_user_defaults(tool) File "project.py", line 67, in apply_user_defaults super().apply_user_defaults(tool) File "/tmp/pip-build-env-lb2ttoa7/overlay/lib/python3.9/site-packages/pyqtbuild/project.py", line 70, in apply_user_defaults super().apply_user_defaults(tool) File "/tmp/pip-build-env-lb2ttoa7/overlay/lib/python3.9/site-packages/sipbuild/project.py", line 236, in apply_user_defaults self.builder.apply_user_defaults(tool) File "/tmp/pip-build-env-lb2ttoa7/overlay/lib/python3.9/site-packages/pyqtbuild/builder.py", line 67, in apply_user_defaults raise PyProjectOptionException('qmake', sipbuild.pyproject.PyProjectOptionException [end of output]note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed× Encountered error while generating package metadata.
╰─> See above for output.note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
解决方法
1. 安装系统级Qt依赖
Chromebook的Linux环境基于Debian/Ubuntu,先安装Qt6的系统开发包:
sudo apt update sudo apt install qt6-base-dev qt6-tools-dev-tools
2. 适配sip版本
错误与sip版本不兼容有关,先卸载现有sip,再安装适配PyQt6的指定版本:
pip3 uninstall -y sip pip3 install sip==6.7.7
3. 重新安装PyQt6
完成上述步骤后执行:
pip3 install pyqt6
备选方案:使用系统包管理器安装
如果上述方法仍失败,直接通过apt安装稳定版PyQt6:
sudo apt install python3-pyqt6
内容的提问来源于stack exchange,提问作者Harrison O'Donnell

