PyQt5模块未找到?

3
这是一次全新的 MacOS 安装!
平台:
Apple MacBook Air - M1
MacOS Monterey

包信息:
Homebrew: 3.3.14
pip: 22.0.3
Python: 3.9.10 (installed via 'brew install python')
Latest-Xcode

我的 $PATH 环境变量:
/opt/homebrew/bin
/opt/homebrew/sbin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

我尝试将这些组合添加到我的 $PATH 中,但没有成功:
/opt/homebrew/lib/python3.9/site-packages
/opt/homebrew/Cellar/pyqt@5/5.15.6/lib/python3.9/site-packages/PyQt5
/opt/homebrew/lib/python3.9/site-packages/PyQt5
/opt/homebrew/opt/pyqt@5/5.15.6/bin
/opt/homebrew/opt/qt@5/5.15.6/bin

我想做的事情:
pip install pyqt5

当我尝试时会发生什么:
  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 "/opt/homebrew/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 "/opt/homebrew/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
          main()
        File "/opt/homebrew/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 "/opt/homebrew/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 "/opt/homebrew/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sipbuild/api.py", line 51, in build_wheel
          project = AbstractProject.bootstrap('pep517')
        File "/opt/homebrew/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sipbuild/abstract_project.py", line 83, in bootstrap
          project.setup(pyproject, tool, tool_description)
        File "/opt/homebrew/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sipbuild/project.py", line 594, in setup
          self.apply_user_defaults(tool)
        File "project.py", line 63, in apply_user_defaults
          super().apply_user_defaults(tool)
        File "/opt/homebrew/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pyqtbuild/project.py", line 70, in apply_user_defaults
          super().apply_user_defaults(tool)
        File "/opt/homebrew/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sipbuild/project.py", line 241, in apply_user_defaults
          self.builder.apply_user_defaults(tool)
        File "/opt/homebrew/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/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.

如果我用这种方式安装,就不会出现错误:
brew install pyqt@5

但是我的 VS Code 显示出来像这样,而且没有任何子模块能够工作:

enter image description here

我的程序以前一直很好用,但最近安装了Python 3.10,后来又卸载了它。自从安装了新的Python之后,我就遇到了这个问题。不知道该怎么解决。谢谢!
3个回答

2

我已经以多种不同的方式在多个地方提出了这个问题,但没有一个建议的答案适用于我。

我得到的最接近答案的东西是这个: https://www.zhihu.com/question/437075754/answer/1993415429

如果您无法阅读它,它建议执行以下操作:

预先安装Homebrew、Python 3.9。

首先在终端中输入:

brew install pyqt5
echo 'export PATH="/opt/homebrew/opt/qt@5/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/opt/homebrew/opt/pyqt@5/5.15.4_1/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

然后,将 /opt/homebrew/Cellar/pyqt@5/5.15.4_1/lib/python3.9/site-packages 文件夹下的所有内容复制到 lib/python3.9/site-packages 文件夹中。如果你的 Homebrew 安装地址和 Python 安装地址不是默认的,你需要修改这两个地址。
最后,在 Python 中尝试它。
import PyQt5

但是这对我也没有起作用。

最终,我只安装了PyQt6:

pip install PyQt6

安装已成功完成,没有任何错误。现在我正在更新我的代码。希望这对那些通过愤怒的谷歌搜索来到这里的其他人有用。继续码字,我的朋友们。

0

我的安装设置如下:

1. brew install qt
2. brew install libxml2

参考 TheCrazySwede 的回答 ↓↓↓

3. brew install pyqt5 插入图片描述

4. brew cleanup pyqt@5

5. echo 'export PATH="/opt/homebrew/opt/qt@5/bin:$PATH"' >> ~/.zshrc

6. echo 'export PATH="/opt/homebrew/opt/pyqt@5/5.15.4_1/bin:$PATH"' >> ~/.zshrc

7. source ~/.zshrc

8. pip3 install pyqt5-sip

9. pip3 install pyqt5 插入图片描述 插入图片描述

10. pip3 install lxml

11. make qt5py3

希望对您有所帮助。


0
我曾经遇到过和你一样的问题,我用以下命令解决了它。

pip3 install pyqt5


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接