12

I have a similar problem as AttributeError: module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel' for PyQt5 5.15.0. Most of the solutions proposed there is to install the latest version of pip. But I have the latest pip version (22.0.2) and it is still not working. I am trying to install it in MacOS 12.1, python version 3.8.9.

Command Output:

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.

Note: Installing PyQt5 with brew worked but brew installed the latest python version as a dependency and I want to install PyQt5 inside my venv.

linkingashu
  • 123
  • 1
  • 1
  • 7

3 Answers3

5

I was also having problems installing PyQt5 on an M1 Mac but found another alternative if you want to use venv without miniconda. Using brew to install python doesn't fix the pip errors when trying to install PyQt5 inside a venv.

The bug actually seems related to using the Python universal installer, and then there appears to be another bug with PyQt5 5.15.6.

First: install Python 3.9.13 MacOS Intel-only installer from python.org After I did this I tried using pip to install the latest version of PyQt (5.15.6) inside the venv but pip flagged a hash mismatch:

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

So Second: use pip install PyQt5==5.15.5

That successfully allowed me to use venv as normal with PyQt5.

EthanMK
  • 68
  • 1
  • 4
  • I tried to install cellpose (https://github.com/MouseLand/cellpose) and used the arm64 version of conda and kept getting errors with the step installing PyQt5. Switching to the X86_64 version did the trick! – Christopher Bottoms May 31 '22 at 19:06
3

So people can find this answer outside of the comments :

Using Brew on macOS works, install both Python and PyQT5 from there, and be sure to change your python command to Brew's directory if you want it to work properly.

I have no idea why, but pip is currently broken on macOS (perhaps all platforms) when installing from python.org

ice-wind
  • 690
  • 4
  • 20
1
  1. 1- check last updates python/pip version
  2. 2- install last version package (pip install pyqt6)
  3. 3- if you need run file QtDesigner just run main python , not ui script

example :

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

and save you ui code in file untitled.ui (dont run ui file format .py) ;D

ellioT
  • 11
  • 2