python-3.x 安装PyQt5时元数据生成失败

wmvff8tz  于 2023-02-06  发布在  Python
关注(0)|答案(3)|浏览(371)

我有一个和AttributeError: module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel' for PyQt5 5.15.0类似的问题,那里提出的解决方案大多是安装最新版本的pip,但是我有最新的pip版本(22.0.2),它仍然不工作,我正在尝试安装在MacOS 12.1,python版本3.8.9。
命令输出:

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: 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/ashuadhikari/Library/Python/3.8/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/ashuadhikari/Library/Python/3.8/lib/python/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
      main()
    File "/Users/ashuadhikari/Library/Python/3.8/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/ashuadhikari/Library/Python/3.8/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/2_/r0h48ntn7x9dz67r08nh7rv80000gn/T/pip-build-env-tp6yyadf/overlay/lib/python3.8/site-packages/sipbuild/api.py", line 51, in build_wheel
      project = AbstractProject.bootstrap('pep517')
    File "/private/var/folders/2_/r0h48ntn7x9dz67r08nh7rv80000gn/T/pip-build-env-tp6yyadf/overlay/lib/python3.8/site-packages/sipbuild/abstract_project.py", line 83, in bootstrap
      project.setup(pyproject, tool, tool_description)
    File "/private/var/folders/2_/r0h48ntn7x9dz67r08nh7rv80000gn/T/pip-build-env-tp6yyadf/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/2_/r0h48ntn7x9dz67r08nh7rv80000gn/T/pip-build-env-tp6yyadf/overlay/lib/python3.8/site-packages/pyqtbuild/project.py", line 70, in apply_user_defaults
      super().apply_user_defaults(tool)
    File "/private/var/folders/2_/r0h48ntn7x9dz67r08nh7rv80000gn/T/pip-build-env-tp6yyadf/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/2_/r0h48ntn7x9dz67r08nh7rv80000gn/T/pip-build-env-tp6yyadf/overlay/lib/python3.8/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安装PyQt5可以,但是brew安装了最新的python版本作为依赖项,我想在我的venv中安装PyQt5。

2ic8powd

2ic8powd1#

我在M1 Mac上安装PyQt5时也遇到了问题,但如果你想使用没有miniconda的venv,我找到了另一种选择。使用brew安装python并不能修复在venv中安装PyQt5时出现的pip错误。
这个bug实际上似乎与Python通用安装程序的使用有关,而且PyQt5 5.15.6似乎还有另一个bug。

第一个:安装Python 3.9.13 MacOS仅限Intel的安装程序python.org安装完成后,我尝试使用pip在venv中安装最新版本的PyQt(5.15.6),但pip标记了一个哈希不匹配:

ERROR: THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE. If you have updated the package versions, please update the hashes. Otherwise, examine the package contents carefully; someone may have tampered with them.
PyQt5-Qt5>=5.15.2 from https://files.pythonhosted.org/packages/62/09/99a222b0360616250fb2e6003a54e43a2a06b0774f0f8d5daafb86a2c375/PyQt5_Qt5-5.15.2-py3-none-macosx_10_13_intel.whl#sha256=76980cd3d7ae87e3c7a33bfebfaee84448fd650bad6840471d6cae199b56e154 (from PyQt5):
    Expected sha256 76980cd3d7ae87e3c7a33bfebfaee84448fd650bad6840471d6cae199b56e154
         Got        d97d141facbdb3af4f5593b5068fb1d57a2e01ccace3758b897636700f2a2640

所以第二个:使用管道安装PyQt5==5.15.5
这成功地允许我在PyQt5中正常使用venv。

uurv41yg

uurv41yg2#

所以人们可以在评论之外找到这个答案:
在macOS上使用Brew是可行的,从那里安装Python和PyQT5,如果希望它正常工作,请确保将python命令更改为Brew的目录。
我不知道为什么,但pip目前在macOS(可能是所有平台)上从www.example.com安装时出现故障python.org

icnyk63a

icnyk63a3#

  1. 1-检查上次更新的python/pip版本
  2. 2-安装最新版本的软件包(pip install pyqt 6
  3. 3-如果需要运行文件QtDesigner,只需运行主Python,而不是UI脚本
    示例:
    main.py:
from PyQt6 import uic
from PyQt6.QtWidgets import QApplication

Form, Window = uic.loadUiType("untitled.ui")

app = QApplication([])
window = Window()
form = Form()
form.setupUi(window)
window.show()
app.exec()

untitled.ui:

from PySide2.QtCore import (QCoreApplication, QMetaObject, QObject, QPoint,
    QRect, QSize, QUrl, Qt)
from PySide2.QtGui import (QBrush, QColor, QConicalGradient, QCursor, QFont,
    QFontDatabase, QIcon, QLinearGradient, QPalette, QPainter, QPixmap,
    QRadialGradient)
from PySide2.QtWidgets import *

class Ui_Frame(object):
    def setupUi(self, Frame):
        if Frame.objectName():
            Frame.setObjectName(u"Frame")
        Frame.resize(640, 480)
        self.pushButton = QPushButton(Frame)
        self.pushButton.setObjectName(u"pushButton")
        self.pushButton.setGeometry(QRect(250, 210, 75, 23))

        self.retranslateUi(Frame)

        QMetaObject.connectSlotsByName(Frame)
    # setupUi

    def retranslateUi(self, Frame):
        Frame.setWindowTitle(QCoreApplication.translate("Frame", u"Frame", None))
        self.pushButton.setText(QCoreApplication.translate("Frame", u"PushButton", None))
    # retranslateUi

并将你的用户界面代码保存在untitled.ui文件中(不要运行用户界面文件格式.py);D级

相关问题