环境:Pycharm+Python3.8(virtualenv)
一直装不上pyqt5,无论是在pycharm里面用它的图形化界面,还是用它下面的terminal,还是在mac 的terminal里面带上绝对路径安装都不行,报错是
(venv) (base) kamianhashiro@kamianhashirodeMacBook-Air pyqt_learn % pip install pyqt5
Collecting pyqt5
Using cached PyQt5-5.15.6.tar.gz (3.2 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... error
ERROR: Command errored out with exit status 1:
command: /Users/kamianhashiro/PycharmProjects/pyqt_learn/venv/bin/python /Users/kamianhashiro/PycharmProjects/pyqt_learn/venv/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py prepare_metadata_for_build_wheel /var/folders/mf/q9hyhjsn7t7cdz18w5ssfpl40000gn/T/tmpk1kk9_om
cwd: /private/var/folders/mf/q9hyhjsn7t7cdz18w5ssfpl40000gn/T/pip-install-dloesh3f/pyqt5_3b0d21adb5e2413bb83c28068a26901a
Complete output (29 lines):
Traceback (most recent call last):
File "/Users/kamianhashiro/PycharmProjects/pyqt_learn/venv/lib/python3.8/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 "/Users/kamianhashiro/PycharmProjects/pyqt_learn/venv/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in
main()
File "/Users/kamianhashiro/PycharmProjects/pyqt_learn/venv/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/Users/kamianhashiro/PycharmProjects/pyqt_learn/venv/lib/python3.8/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 "/private/var/folders/mf/q9hyhjsn7t7cdz18w5ssfpl40000gn/T/pip-build-env-natmcxko/overlay/lib/python3.8/site-packages/sipbuild/api.py", line 51, in build_wheel
project = AbstractProject.bootstrap('pep517')
File "/private/var/folders/mf/q9hyhjsn7t7cdz18w5ssfpl40000gn/T/pip-build-env-natmcxko/overlay/lib/python3.8/site-packages/sipbuild/abstract_project.py", line 83, in bootstrap
project.setup(pyproject, tool, tool_description)
File "/private/var/folders/mf/q9hyhjsn7t7cdz18w5ssfpl40000gn/T/pip-build-env-natmcxko/overlay/lib/python3.8/site-packages/sipbuild/project.py", line 587, in setup
self.apply_user_defaults(tool)
File "project.py", line 63, in apply_user_defaults
super().apply_user_defaults(tool)
File "/private/var/folders/mf/q9hyhjsn7t7cdz18w5ssfpl40000gn/T/pip-build-env-natmcxko/overlay/lib/python3.8/site-packages/pyqtbuild/project.py", line 70, in apply_user_defaults
super().apply_user_defaults(tool)
File "/private/var/folders/mf/q9hyhjsn7t7cdz18w5ssfpl40000gn/T/pip-build-env-natmcxko/overlay/lib/python3.8/site-packages/sipbuild/project.py", line 234, in apply_user_defaults
self.builder.apply_user_defaults(tool)
File "/private/var/folders/mf/q9hyhjsn7t7cdz18w5ssfpl40000gn/T/pip-build-env-natmcxko/overlay/lib/python3.8/site-packages/pyqtbuild/builder.py", line 67, in apply_user_defaults
raise PyProjectOptionException('qmake',
sipbuild.pyproject.PyProjectOptionException
----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/3b/27/fd81188a35f37be9b3b4c2db1654d9439d1418823916fe702ac3658c9c41/PyQt5-5.15.6.tar.gz#sha256=80343bcab95ffba619f2ed2467fd828ffeb0a251ad7225be5fc06dcc333af452 (from https://pypi.org/simple/pyqt5/) (requires-python:>=3.6). Command errored out with exit status 1: /Users/kamianhashiro/PycharmProjects/pyqt_learn/venv/bin/python /Users/kamianhashiro/PycharmProjects/pyqt_learn/venv/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py prepare_metadata_for_build_wheel /var/folders/mf/q9hyhjsn7t7cdz18w5ssfpl40000gn/T/tmpk1kk9_om Check the logs for full command output.
Using cached PyQt5-5.15.5.tar.gz (3.2 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... error
ERROR: Command errored out with exit status 1:
command: /Users/kamianhashiro/PycharmProjects/pyqt_learn/venv/bin/python /Users/kamianhashiro/PycharmProjects/pyqt_learn/venv/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py prepare_metadata_for_build_wheel /var/folders/mf/q9hyhjsn7t7cdz18w5ssfpl40000gn/T/tmpth0w9vx1
cwd: /private/var/folders/mf/q9hyhjsn7t7cdz18w5ssfpl40000gn/T/pip-install-dloesh3f/pyqt5_c94d2621e85f4938b2c798e91e7cdd7f
Complete output (29 lines):
Traceback (most recent call last):
File "/Users/kamianhashiro/PycharmProjects/pyqt_learn/venv/lib/python3.8/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 "/Users/kamianhashiro/PycharmProjects/pyqt_learn/venv/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in
main()
File "/Users/kamianhashiro/PycharmProjects/pyqt_learn/venv/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/Users/kamianhashiro/PycharmProjects/pyqt_learn/venv/lib/python3.8/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 "/private/var/folders/mf/q9hyhjsn7t7cdz18w5ssfpl40000gn/T/pip-build-env-_lzbi59s/overlay/lib/python3.8/site-packages/sipbuild/api.py", line 51, in build_wheel
project = AbstractProject.bootstrap('pep517')
File "/private/var/folders/mf/q9hyhjsn7t7cdz18w5ssfpl40000gn/T/pip-build-env-_lzbi59s/overlay/lib/python3.8/site-packages/sipbuild/abstract_project.py", line 83, in bootstrap
project.setup(pyproject, tool, tool_description)
File "/private/var/folders/mf/q9hyhjsn7t7cdz18w5ssfpl40000gn/T/pip-build-env-_lzbi59s/overlay/lib/python3.8/site-packages/sipbuild/project.py", line 587, in setup
self.apply_user_defaults(tool)
File "project.py", line 63, in apply_user_defaults
super().apply_user_defaults(tool)
File "/private/var/folders/mf/q9hyhjsn7t7cdz18w5ssfpl40000gn/T/pip-build-env-_lzbi59s/overlay/lib/python3.8/site-packages/pyqtbuild/project.py", line 70, in apply_user_defaults
super().apply_user_defaults(tool)
File "/private/var/folders/mf/q9hyhjsn7t7cdz18w5ssfpl40000gn/T/pip-build-env-_lzbi59s/overlay/lib/python3.8/site-packages/sipbuild/project.py", line 234, in apply_user_defaults
self.builder.apply_user_defaults(tool)
File "/private/var/folders/mf/q9hyhjsn7t7cdz18w5ssfpl40000gn/T/pip-build-env-_lzbi59s/overlay/lib/python3.8/site-packages/pyqtbuild/builder.py", line 67, in apply_user_defaults
raise PyProjectOptionException('qmake',
sipbuild.pyproject.PyProjectOptionException
----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/72/bf/4e7c66eefa9ede1ec01d065d220373667f4ca3285a83a6430eefc254904c/PyQt5-5.15.5.tar.gz#sha256=b411b7a8fa03901c9feb1dcbac7ea1fc3ce20b9ae682762b777cd5398749ca2b (from https://pypi.org/simple/pyqt5/) (requires-python:>=3.6). Command errored out with exit status 1: /Users/kamianhashiro/PycharmProjects/pyqt_learn/venv/bin/python /Users/kamianhashiro/PycharmProjects/pyqt_learn/venv/lib/python3.8/site-packages/pip/_vendor/pep517/in_process/_in_process.py prepare_metadata_for_build_wheel /var/folders/mf/q9hyhjsn7t7cdz18w5ssfpl40000gn/T/tmpth0w9vx1 Check the logs for full command output.
(后面还有很长,反正就是将所有的版本都试了一遍,大同小异的样子)
根据报错信息,和stack overflow上面的提示(stack overflow上面的那位好像是想在树莓派上面安装pyqt5,评论区告诉他让他更新pip版本和试试sudo,但是他没有反馈是否work),先后尝试过升级pip版本、降低pip版本的方法都不能安装,sudo也不行。
随后偶尔发现自己菜鸟的时候在命令行里面乱写,导致python的默认环境变量是annaconda的环境变量,装到了conda环境里面,意外地发现将解释器修改为conda环境的3.9是可以使用的,但是个人原因不想在conda环境下用pyqt,还是想继续尝试在python3.8环境下安装pyqt,查到了这篇文章,对于了解 pyproject.toml到底是什么东西?
有帮助,在此记录一下
下面给出最终解决方案(莫名其妙就行了,也不知道为什么,如果你也面临同样的问题或者知道具体的原因请务必告诉我)
ps:我的homebrew也是3.9的环境
PYQT5 安装遇到的坑_alai986的博客-CSDN博客
根据上面那篇文章,brew安装pyqt@5,报错。
(base) kamianhashiro@kamianhashirodeMacBook-Air bin % brew install pyqt@5
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/bottles/qt%405-5.15.2.arm64_big_sur.bottle.1.tar.gz
#=#=#
curl: (22) The requested URL returned error: 404
Warning: Bottle missing, falling back to the default domain...
==> Downloading https://ghcr.io/v2/homebrew/core/qt/5/manifests/5.15.2-1
Already downloaded: /Users/kamianhashiro/Library/Caches/Homebrew/downloads/52d013cb38bd94cbfa72f0035bdefff1fc46e3cf0fe5e0af0688f0ec3779a31e--qt@5-5.15.2-1.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/qt/5/blobs/sha256:6128558bbf98848bb762d8e1e532303b694bf120d4f9be16e1a969ba62fa3d22
Already downloaded: /Users/kamianhashiro/Library/Caches/Homebrew/downloads/4a529abbe9a6f09250c66f3e4dc967ce0da456c0d44028b21d15374fa81389e8--qt@5--5.15.2.arm64_big_sur.bottle.1.tar.gz
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/bottles/pyqt%405-5.15.4_2.arm64_big_sur.bottle.tar.gz
Already downloaded: /Users/kamianhashiro/Library/Caches/Homebrew/downloads/98acd931ff075718c8a695aa6c7ed5bd534a761034ed430fd77d5fe1863f9cb9--pyqt@5-5.15.4_2.arm64_big_sur.bottle.tar.gz
==> Installing dependencies for pyqt@5: qt@5
==> Installing pyqt@5 dependency: qt@5
==> Pouring [email protected]_big_sur.bottle.1.tar.gz
tar: Error opening archive: Failed to open '/Users/kamianhashiro/Library/Caches/Homebrew/downloads/b8be74166a0baf11aa9c9fbebc9453c4e688b07dcc65be8f8483844ee362584c--qt@5-5.15.2.arm64_big_sur.bottle.1.tar.gz'
Error: Failure while executing; `tar --extract --no-same-owner --file /Users/kamianhashiro/Library/Caches/Homebrew/downloads/b8be74166a0baf11aa9c9fbebc9453c4e688b07dcc65be8f8483844ee362584c--qt@5-5.15.2.arm64_big_sur.bottle.1.tar.gz --directory /private/tmp/d20211030-71035-16lu35n` exited with 1. Here's the output:
tar: Error opening archive: Failed to open '/Users/kamianhashiro/Library/Caches/Homebrew/downloads/b8be74166a0baf11aa9c9fbebc9453c4e688b07dcc65be8f8483844ee362584c--qt@5-5.15.2.arm64_big_sur.bottle.1.tar.gz'
随后brew安装qt@5
(base) kamianhashiro@kamianhashirodeMacBook-Air bin % brew install qt@5
==> Downloading https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/bottles/qt%405-5.15.2.arm64_big_sur.bottle.1.tar.gz
curl: (22) The requested URL returned error: 404
Warning: Bottle missing, falling back to the default domain...
==> Downloading https://ghcr.io/v2/homebrew/core/qt/5/manifests/5.15.2-1
Already downloaded: /Users/kamianhashiro/Library/Caches/Homebrew/downloads/52d013cb38bd94cbfa72f0035bdefff1fc46e3cf0fe5e0af0688f0ec3779a31e--qt@5-5.15.2-1.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/qt/5/blobs/sha256:6128558bbf98848bb762d8e1e532303b694bf120d4f9be16e1a969ba62fa3d22
Already downloaded: /Users/kamianhashiro/Library/Caches/Homebrew/downloads/4a529abbe9a6f09250c66f3e4dc967ce0da456c0d44028b21d15374fa81389e8--qt@5--5.15.2.arm64_big_sur.bottle.1.tar.gz
==> Pouring [email protected]_big_sur.bottle.1.tar.gz
==> Caveats
We agreed to the Qt open source license for you.
If this is unacceptable you should uninstall.
This version of Qt on Apple Silicon does not include QtWebEngine
qt@5 is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.
If you need to have qt@5 first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/qt@5/bin:$PATH"' >> ~/.zshrc
For compilers to find qt@5 you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/qt@5/lib"
export CPPFLAGS="-I/opt/homebrew/opt/qt@5/include"
For pkg-config to find qt@5 you may need to set:
export PKG_CONFIG_PATH="/opt/homebrew/opt/qt@5/lib/pkgconfig"
==> Summary
/opt/homebrew/Cellar/qt@5/5.15.2: 10,466 files, 191.7MB
==> `brew cleanup` has not been run in the last 30 days, running now...
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/pkg-config... (64B)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/libtiff... (64B)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/libpng... (64B)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/gdbm... (64B)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/mpdecimal... (64B)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/freetype... (64B)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/libvorbis... (64B)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/sdl_image... (64B)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/libogg... (64B)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/libmikmod... (64B)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/readline... (64B)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/portmidi... (64B)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/webp... (64B)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/sqlite... (64B)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/sdl_ttf... (64B)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/xz... (64B)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/flac... (64B)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/smpeg... (64B)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/sdl... (64B)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/mercurial... (64B)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/[email protected]... (64B)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/jpeg... (64B)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/nmap... (64B)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/sdl2... (64B)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/[email protected]... (2 files, 2.5KB)
Removing: /Users/kamianhashiro/Library/Logs/Homebrew/sdl_mixer... (64B)
Pruned 0 symbolic links and 2 directories from /opt/homebrew
之后又brew install qt试了试,是报错的,等于没多大影响(为了确保之后能复现,在这里记录一下)
然后根据文章中的内容,将brew里面的pyqt5复制到了virtualenv环境的site-package里面,运行的时候不报找不到pyqt5模块的错误了,但是报错的是找不到pyqt5-sig
查看目录发现pyqt5-sig后面有个py3.9,应该是我在brew里面装的时候brew的环境是3.9造成的,于是尝试了在pycharm里面安装pyqt5-sig,装sig没有报错安装成功,跑下面这个测试代码是能跑的,随后又尝试了将带有3.9的那个复制过来的sig文件夹删除,也能正常的运行测试代码,可以暂时认为pyqt5安装成功了
附:测试代码
# -*- coding: utf-8 -*-
import sys
from PyQt5 import QtWidgets, QtCore
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
widget = QtWidgets.QWidget()
widget.resize(320, 240)
widget.setWindowTitle("Hello PyQt5")
widget.show()
sys.exit(app.exec_())
目前不知道这一系列现象发生的原因,有知道的dalao还希望能告诉我一声。