63

A program I am trying to install requires the installation of PyQt5 5.15.0 , which gives me this error. The odd thing is that the installation works fine for the latest version of PyQt5 (5.15.2), but this program requires 5.15.0 specifically.

Command Output:

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
    Preparing wheel metadata ... error
    ERROR: Command errored out with exit status 1:
     command: 'c:\users\mshal\appdata\local\programs\python\python39\python.exe' 'C:\Users\mshal\AppData\Roaming\Python\Python39\site-packages\pip\_vendor\pep517\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\mshal\AppData\Local\Temp\tmp41s11ev6'
         cwd: C:\Users\mshal\AppData\Local\Temp\pip-install-sfw90hvc\pyqt5_e2cc46859b554da7b84798abae5378ba
    Complete output (31 lines):
    Traceback (most recent call last):
      File "C:\Users\mshal\AppData\Roaming\Python\Python39\site-packages\pip\_vendor\pep517\_in_process.py", line 126, 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 "C:\Users\mshal\AppData\Roaming\Python\Python39\site-packages\pip\_vendor\pep517\_in_process.py", line 280, in <module>
        main()
      File "C:\Users\mshal\AppData\Roaming\Python\Python39\site-packages\pip\_vendor\pep517\_in_process.py", line 263, in main
        json_out['return_val'] = hook(**hook_input['kwargs'])
      File "C:\Users\mshal\AppData\Roaming\Python\Python39\site-packages\pip\_vendor\pep517\_in_process.py", line 130, in prepare_metadata_for_build_wheel
        return _get_wheel_metadata_from_wheel(backend, metadata_directory,
      File "C:\Users\mshal\AppData\Roaming\Python\Python39\site-packages\pip\_vendor\pep517\_in_process.py", line 159, in _get_wheel_metadata_from_wheel
        whl_basename = backend.build_wheel(metadata_directory, config_settings)
      File "C:\Users\mshal\AppData\Local\Temp\pip-build-env-nnx_yu09\overlay\Lib\site-packages\sipbuild\api.py", line 51, in build_wheel
        project = AbstractProject.bootstrap('pep517')
      File "C:\Users\mshal\AppData\Local\Temp\pip-build-env-nnx_yu09\overlay\Lib\site-packages\sipbuild\abstract_project.py", line 83, in bootstrap
        project.setup(pyproject, tool, tool_description)
      File "C:\Users\mshal\AppData\Local\Temp\pip-build-env-nnx_yu09\overlay\Lib\site-packages\sipbuild\project.py", line 479, in setup
        self.apply_user_defaults(tool)
      File "project.py", line 62, in apply_user_defaults
        super().apply_user_defaults(tool)
      File "C:\Users\mshal\AppData\Local\Temp\pip-build-env-nnx_yu09\overlay\Lib\site-packages\pyqtbuild\project.py", line 79, in apply_user_defaults
        super().apply_user_defaults(tool)
      File "C:\Users\mshal\AppData\Local\Temp\pip-build-env-nnx_yu09\overlay\Lib\site-packages\sipbuild\project.py", line 225, in apply_user_defaults
        self.builder.apply_user_defaults(tool)
      File "C:\Users\mshal\AppData\Local\Temp\pip-build-env-nnx_yu09\overlay\Lib\site-packages\pyqtbuild\builder.py", line 66, in apply_user_defaults
        raise PyProjectOptionException('qmake',
    sipbuild.pyproject.PyProjectOptionException
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\mshal\appdata\local\programs\python\python39\python.exe' 'C:\Users\mshal\AppData\Roaming\Python\Python39\site-packages\pip\_vendor\pep517\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\mshal\AppData\Local\Temp\tmp41s11ev6' Check the logs for full command output.

I am on the latest version of pip. Any ideas on the root cause of this issue?

thecrispywisp
  • 631
  • 1
  • 4
  • 3
  • 6
    try first upgrade pip: `sudo python3 -m pip install --upgrade pip` and then `sudo python3 -m pip install pyqt5` – eyllanesc Dec 25 '20 at 15:07
  • 1
    @eyllanesc it says sudo is not recognized as an internal command. I am on windows btw, but my pip is installed to the latest version i just checked – thecrispywisp Dec 25 '20 at 15:36
  • 2
    Have the same problem as you on a Raspberry Pi (Linux) and none of the answers work. Error message keeps showing regardless of the suggestions given bellow.. – Vasco Cansado Carvalho Dec 02 '21 at 01:14
  • 3
    Possibly, installing `pyqt-sip` first might help? `python3 -m pip install pyqt-sip` – APaul Dec 27 '21 at 19:41
  • 1
    This topic has been answered in https://stackoverflow.com/questions/65901162/how-can-i-run-pyqt5-on-my-mac-with-m1chip – Jari Turkia Apr 27 '22 at 09:21

14 Answers14

37

What helped me is upgrading pip from 20.2.3 to the latest one (in my case 21.1.1)

Lukasz Czerwinski
  • 13,499
  • 10
  • 55
  • 65
  • 5
    I was trying to install PyQt5 inside a virtual environment using Python 3.8.2 and pip 19.2.3. Then I ran `pip install --upgrade pip` and upgraded to pip-21.1.2, and I was able to install PyQt5 without issue. – ChaserAide Jun 19 '21 at 01:38
21

For Mac/Homebrew users.

The answer by @the-x is leading in the right direction. On a Mac with QT5 installed via Homebrew the qmake binary just needs to be added to the path. This can be achieved through

export PATH="/opt/homebrew/opt/qt5/bin:$PATH"

(of course depending on where the homebrew files are installed)

kontur
  • 4,934
  • 2
  • 36
  • 62
WuAn
  • 211
  • 2
  • 4
  • 2
    This resolved it for me. qt5 path can be found with `brew --prefix qt` – Chris Aug 12 '22 at 20:12
  • 1
    As per @Voljum 's [answer](https://stackoverflow.com/a/74483436/999162) and [this answer on the more specific question](https://stackoverflow.com/questions/73714829/pip-install-pyqt5-it-cannot-go-on), you will still need to accept the pyqt license, e.g. install with `pip install pyqt5 --config-settings --confirm-license= --verbose` – kontur Dec 30 '22 at 10:14
11

Running on arm with python3.6 (ubuntu18 on nvidia Xavier):

sudo apt install qt5-default
Y A
  • 111
  • 1
  • 3
  • 1
    This should be the selected answer, if QT5 is not installed on the host or there is a large enough version gap the metadata just won't exist or be valid. – Mark Carpenter Jr Dec 27 '21 at 17:33
9

For MacOS users.

I am on Apple M1 silicon using Python 3.9.8. What worked for me was @Apaul's comment in the original question section. Install pyqt5-sip prior to pyqt5.

I also have an Intel Mac and on that machine, I do not need to do this.

ejkitchen
  • 559
  • 6
  • 11
  • 1
    i try install pyqt5-sip,then install pyqt5,but fail,error message note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed – xin.chen Mar 10 '22 at 16:01
  • Are you on a Mac with M1 or Intel? – ejkitchen Mar 11 '22 at 21:51
  • on a Mac with M1 – xin.chen Mar 12 '22 at 15:31
  • 25
    Trying to fix the problem with `pip install pyqt5-sip` does not change anything on my M1 mac. Error module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel' remains. – Jari Turkia Apr 27 '22 at 09:06
  • 1
    Unfortunately problem still exists. Any idea how to get it fixed? I am trying to install Spyder command line – Korpel Oct 20 '22 at 14:22
  • Hi @Korpel, I've just posted an answer that works on Apple Mac (the example is given with the pixellib library but is a general one) – mPrinC Dec 02 '22 at 01:28
7

Checking the binaries that PyQt5 provides in pypi for version 5.15.0 I see that it does not provide the binaries for python3.9 in windows, so pip is trying to compile using the source code which is complicated and can generate several dependency problems (for example you must have Qt 5.15 installed, etc). So my recommendation is to install a more updated version of PyQt5, for example 5.15.2 since if it provides the binaries for python3.9 on windows, in addition to being a wrapper of an LTS version of Qt then it will have solved several bugs.

python -m pip install PyQt5==5.15.2

Another solution is to use python3.8 instead of python3.9 so that you can install pyqt5 5.15.0 from pypi without problems.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • That makes sense! I already installed version 5.15.2 and it works just fine, but the program I am trying to use keeps trying to download 5.15.0 for some reason, even if I already have 5.15.2 installed. Would that be a problem with that specific program itself then? – thecrispywisp Dec 25 '20 at 16:16
  • @thecrispywisp 1) Read my updated post, 2) It seems that some dependency is very strict (besides being silly) since the codebase of Qt 5.15.0 and Qt 5.15.2 is the same, only that Qt 5.15.2 solves several bugs of Qt 5.15.0, if you tell me what program it is (or the repository) then I would try to investigate what should be modified so that it no longer asks you for that specific version. – eyllanesc Dec 25 '20 at 16:20
  • I really appreciate the detailed answer, that makes sense. The program is called RLBot https://rlbot.org/ , and I am using the windows version. – thecrispywisp Dec 25 '20 at 16:38
  • @thecrispywisp How are you installed RLBot? On the other hand I think the simplest thing is to use option2 of my answer: uninstall python3.9 and use python3.8, then install pyqt5 5.15.0 – eyllanesc Dec 25 '20 at 16:47
  • If you follow the link its the "Download RLbot for Windows", and thanks for the input! I am going to do that right now – thecrispywisp Dec 25 '20 at 16:51
  • Is there a way to downgrade python directly without losing my libraries? – thecrispywisp Dec 25 '20 at 17:15
  • @thecrispywisp No, You can not – eyllanesc Dec 25 '20 at 17:15
  • Alright, thanks a ton for your patience with me! I will probably wait for the program to be fixed as it is not worth the hassle of redownloading my libraries rn. I really appreciate your time! – thecrispywisp Dec 25 '20 at 17:23
4

Upgrading your pip enables you to install PyQt5. Personally, I had the same issue while installing PyQt6 and I upgraded my pip, and everything installed perfectly. I think both python and pip versions play an important role in installing PyQt so make sure you have later versions.

This is the command I used in Linux:

pip install --upgrade pip
Shayan Shafiq
  • 1,447
  • 5
  • 18
  • 25
4

Combining several answers on this question: On an Apple M1 Pro Macbook with macOS Ventura 13.0.1, with Homebrew 3.6.17 and python 3.11.0 the following commands fixed it for me (no sudo):

brew install qt5
export PATH="/opt/homebrew/opt/qt5/bin:$PATH"
python3 -m ensurepip --default-pip
pip3 install pyqt5-sip
pip3 install pyqt5 --config-settings --confirm-license= --verbose

That last step calls qmake to compile all of Qt on your M1 and takes many minutes to complete, be patient and let it finish.

Rolf
  • 7,098
  • 5
  • 38
  • 55
3

To all those that are struggling with Apple M1 installation, here is a working solution, specifically addressing the problem of installing the pixellib library that depends on PyQt5 but you can apply it equally to other libs:

  1. PyQt5 is not supported on Apple M1, it needs qt6: https://www.reddit.com/r/learnpython/comments/o4w1ut/comment/h2jele3/?utm_source=share&utm_medium=web2x&context=3 , https://www.qt.io/product/qt6
  2. this means you need to install PyQt6: python3 -m pip install PyQt6
  3. go to the lib you need, in my case pixellib: https://pypi.org/project/pixellib/#files and
  4. download the wheel file
  5. get the wheel tool: pip install wheel
  6. unpack the wheel wheel unpack pixellib-0.7.1-py3-none-any.whl
  7. Change its dependency of PyQt5 to PyQt6
    1. edit pixellib-0.7.1/pixellib-0.7.1.dist-info/METADATA
    2. pyQt5 => pyQt6
  8. pack it back wheel pack pixellib-0.7.1
  9. install it: pip install pixellib-0.7.1-py3-none-any.whl
  10. test in python: `
# should work
import pixellib

P.S. thanks to Terra and ChaOS for supporting work on the project underlying this report.

mPrinC
  • 9,147
  • 2
  • 32
  • 31
  • This is making the assumption pyqt5 and pyqt6 are interchangeable for the project you are trying to install, which they may not. – kontur Dec 30 '22 at 09:50
1

Since qt5-default was not available, I installed qt5-default's dependencies

sudo apt-get install qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools

after that I installed pyqt5 via apt-get first and afterwards via pip

sudo apt-get install pyqt5-dev
pip install pyqt5

now wheel seems to work


side-note:

  • I am not sure if sudo apt-get install pyqt5-dev is even necessary
cagcoach
  • 625
  • 7
  • 24
1

The error message thrown here is misleading - it's not an issue with a sipbuild.api attribute. Indeed, in this case program qmake is missing, see last line of the Python traceback. Have a look if it's installed on your system and add it to your PATH variable. Otherwise, install it. On Linux this would be done with

sudo apt-get install qt5-qmake
the-x
  • 11
  • 1
1

I had this problem on my M1 Mac using Python 3.9.12 when I was trying to install a library: pip install pixellib. The first thing I did was: pip install pixellib --verbose to see the whole log, and there I noticed that PyQt5 was waiting for an input. So then I found someone else with that issue, and used pip install pyqt5 --config-settings --confirm-license= --verbose which took some time to compile, but worked!

Voljum
  • 51
  • 3
0

I could not get any of the above solutions to work but I managed to get it working using python3.9, PyQt5=5.15.2, pip=22.0.2 and sip=6.5.0 by using sudo apt-get install PyQt5. If you need it in a virtual environment, you can manually copy the PyQt5 folder from your default /usr/lib/python3/dist-packages to the site-packages folder in your virtual environment.

M.K
  • 1,464
  • 2
  • 24
  • 46
Simon Dreyer
  • 43
  • 1
  • 8
0

I finally managed to make it works on M1/M2 Macbook Pro.
None of these answers worked for me, so I looked at brew to install pyqt.
The following command will install pyqt5 via brew:

brew install pyqt@5

Then it just worked.

VivienG
  • 2,143
  • 3
  • 24
  • 43
  • This got me past the error but now the install just hangs at `preparing metadata (pyproject.toml)`, even in a brand new virtualenv. – trpt4him Feb 20 '23 at 18:54
  • Already had the same here, check your RAM/swap usage. In my case it was due to DNS issue due to my VPN IIRC. – VivienG Feb 21 '23 at 16:23
  • In my case I needed to switch to x86_64 architecture: `arch -x86_64 $SHELL` – trpt4him Feb 24 '23 at 20:00
  • I definitely not fond of doing this as it can lead to strange behaviour in the future. – VivienG Feb 27 '23 at 13:12
-7

This can be resolved by switching to an environment with Python >= 3.8

user48956
  • 14,850
  • 19
  • 93
  • 154