Solving PyQt5 AttributeError: module ‘sipbuild.api’ has no attribute ‘prepare_metadata_for_build_wheel’

AttributeError: module ‘sipbuild.api’ has no attribute ‘prepare_metadata_for_build_wheel’ is an error which occurs in Python when the PyQt5 installation is faulty.

In this article I am going to show you why this error is happening and how you can solve this error. I am also going to share with you other possible solutions which have worked for many developers who suffered from this error.

Explaining the Error : AttributeError: module ‘sipbuild.api’ has no attribute ‘prepare_metadata_for_build_wheel’

First of all we need to understand why the error happens at all, the error happens when you try to install some versions of PyQt5.

Please make sure the error message you are having is the same or at last very similar to the error message bellow. The goal here is to not confuse python errors and try solving an error using the fix of another. Which is not going to lead us anywhere.

                                                                       #
Collecting PyQt5==5.15.0
  Using cached PyQt5-5.15.0.tar.gz (3.3 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
...
    Complete output (31 lines):
    Traceback (most recent call last):
...
        whl_basename = backend.build_wheel(metadata_directory, config_settings)
...
'C:\Users\achg\AppData\Local\Temp\tmp41s11ev6' Check the logs for full command output.
                                                                       #

Bellow are the solutions which have worked for me and will help you to successfully get rid of the error.

Solution 1 : pyqt5 and pyqt-sip installation.

This is a step by step solution, so please make sure to follow the instructions bellow step by step.

First, you should start by upgrading pip:

                                                                       #
sudo python3 -m pip install 
                                                                       #

Then install pyqt5 using the command bellow.

                                                                       #
sudo python3 -m pip install pyqt5
                                                                       #

If that did not help, try installing pyqt-sip.

                                                                       #
python3 -m pip install pyqt-sip
                                                                       #

The series of commands should be enough to solve the issue. If that is not the case please try the solution bellow.

Solution 2 : last version of PyQt5 or downgrade python.

The second solution is to install one of the latest versions of PyQt5. It provides the binaries for python3.9 on windows and has an LTS version of Qt which will solve several bugs.

                                                                       #
python -m pip install PyQt5==5.15.2
                                                                       #

Another solution is to downgrade your version of python. For example you can downgrade from python 3.9 to python3.7 or python3.8.

Then install PyQt and it should work. Otherwise try the solution bellow.

Solution 3 : install qt5-default

If the solutions above did not work a last attempt could be installing qt5-default using the command bellow.

                                                                       #
sudo apt install qt5-default
                                                                       #

This solution should work and should be enough to get rid of the error for good.

Summing-up

Friends, I hope this article was helpful and help you in any way, shape or form, the first solution worked for me and also the third, depending on your case the solution could be different, just keep trying and do not give up, keep coding, cheers.

If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/