macos无法安装PyQt5,什么原因呢?

macname ~ % pip install PyQt5
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.org/simple/
Collecting PyQt5
  Using cached PyQt5-5.15.7.tar.gz (3.2 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 "/Users/macname/Library/Python/3.9/lib/python/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/macname/Library/Python/3.9/lib/python/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
          main()
        File "/Users/macname/Library/Python/3.9/lib/python/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/Users/macname/Library/Python/3.9/lib/python/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/j8/ysh91mwn5bs3kd08n7fhx_tw0000gn/T/pip-build-env-1w692pk8/overlay/lib/python3.9/site-packages/sipbuild/api.py", line 46, in build_wheel
          project = AbstractProject.bootstrap('wheel',
        File "/private/var/folders/j8/ysh91mwn5bs3kd08n7fhx_tw0000gn/T/pip-build-env-1w692pk8/overlay/lib/python3.9/site-packages/sipbuild/abstract_project.py", line 87, in bootstrap
          project.setup(pyproject, tool, tool_description)
        File "/private/var/folders/j8/ysh91mwn5bs3kd08n7fhx_tw0000gn/T/pip-build-env-1w692pk8/overlay/lib/python3.9/site-packages/sipbuild/project.py", line 585, in setup
          self.apply_user_defaults(tool)
        File "project.py", line 69, in apply_user_defaults
          super().apply_user_defaults(tool)
        File "/private/var/folders/j8/ysh91mwn5bs3kd08n7fhx_tw0000gn/T/pip-build-env-1w692pk8/overlay/lib/python3.9/site-packages/pyqtbuild/project.py", line 70, in apply_user_defaults
          super().apply_user_defaults(tool)
        File "/private/var/folders/j8/ysh91mwn5bs3kd08n7fhx_tw0000gn/T/pip-build-env-1w692pk8/overlay/lib/python3.9/site-packages/sipbuild/project.py", line 236, in apply_user_defaults
          self.builder.apply_user_defaults(tool)
        File "/private/var/folders/j8/ysh91mwn5bs3kd08n7fhx_tw0000gn/T/pip-build-env-1w692pk8/overlay/lib/python3.9/site-packages/pyqtbuild/builder.py", line 69, 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.

无法安装PyQt5,不知道啥原因,感谢高手指出

阅读 7.4k
1 个回答

尝试直接使用 brew 安装:

brew install pyqt@5

网上是有说不支持 python3.8 以上,但是我安装了 pyqt@5 后,发现安装目录下面的 lib,存在两个目录 python3.9python3.10
image.png

从这上面看,应该是支持的,pip 安装失败的原因还不清楚,可以尝试使用一下 brew 安装的 lib 看看。

更新

我看了一下 PyQt5安装介绍

pip install PyQt5

pip will also build and install the bindings from the sdist package but Qt’s qmake tool must be on PATH.

上面提到了,要安装 PyQt5 需要有 qmake 可执行文件。

mac 下 使用 brew 获取 qmake 可执行文件:

brew install qt5
brew link qt5 --force

不过我测试下来,发现错误是没了,不过就卡在 Preparing metadata (pyproject.toml) ... - 这一步不动了,你可以试试看。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题