Search code examples
pythonraspberry-pipyqtpyqt6

Installing PyQt6 on Raspberry Pi


When I try to install the PyQt6 library on Raspberry Pi using pip (command "pip install PyQt6") I get the following error:

AttributeError: module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel'

Here is the full result:

Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting PyQt6
  Using cached PyQt6-6.4.2.tar.gz (1.0 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 /tmp/tmpg8vbytn0_in_process.py prepare_metadata_for_build_wheel /tmp/tmpibnxfxlu
         cwd: /tmp/pip-install-ahxh_8fa/pyqt6_64f704c0d362442abcae9385cfcd89c0
    Complete output (31 lines):
    Traceback (most recent call last):
      File "/tmp/tmpg8vbytn0_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 "/tmp/tmpg8vbytn0_in_process.py", line 280, in <module>
        main()
      File "/tmp/tmpg8vbytn0_in_process.py", line 263, in main
        json_out['return_val'] = hook(**hook_input['kwargs'])
      File "/tmp/tmpg8vbytn0_in_process.py", line 130, in prepare_metadata_for_build_wheel
        return _get_wheel_metadata_from_wheel(backend, metadata_directory,
      File "/tmp/tmpg8vbytn0_in_process.py", line 159, in _get_wheel_metadata_from_wheel
        whl_basename = backend.build_wheel(metadata_directory, config_settings)
      File "/tmp/pip-build-env-5i1i4ta7/overlay/lib/python3.9/site-packages/sipbuild/api.py", line 46, in build_wheel
        project = AbstractProject.bootstrap('wheel',
      File "/tmp/pip-build-env-5i1i4ta7/overlay/lib/python3.9/site-packages/sipbuild/abstract_project.py", line 87, in bootstrap
        project.setup(pyproject, tool, tool_description)
      File "/tmp/pip-build-env-5i1i4ta7/overlay/lib/python3.9/site-packages/sipbuild/project.py", line 585, in setup
        self.apply_user_defaults(tool)
      File "project.py", line 65, in apply_user_defaults
        super().apply_user_defaults(tool)
      File "/tmp/pip-build-env-5i1i4ta7/overlay/lib/python3.9/site-packages/pyqtbuild/project.py", line 70, in apply_user_defaults
        super().apply_user_defaults(tool)
      File "/tmp/pip-build-env-5i1i4ta7/overlay/lib/python3.9/site-packages/sipbuild/project.py", line 236, in apply_user_defaults
        self.builder.apply_user_defaults(tool)
      File "/tmp/pip-build-env-5i1i4ta7/overlay/lib/python3.9/site-packages/pyqtbuild/builder.py", line 69, in apply_user_defaults
        raise PyProjectOptionException('qmake',
    sipbuild.pyproject.PyProjectOptionException
    ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/c3/e0/e1b592a6253712721612e2e64a323930a724e1f5cf297ed5ec6d6c86dda1/PyQt6-6.4.2.tar.gz#sha256=740244f608fe15ee1d89695c43f31a14caeca41c4f02ac36c86dfba4a5d5813d (from https://pypi.org/simple/pyqt6/) (requires-python:>=3.6.1). Command errored out with exit status 1: /usr/bin/python3 /tmp/tmpg8vbytn0_in_process.py prepare_metadata_for_build_wheel /tmp/tmpibnxfxlu Check the logs for full command output

I updated pip from version 20.3.4 to 23.0.1. And the console issued the following content:

Preparing metadata (pyproject.toml) did not run successfully.

Full version:

Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting PyQt6
  Using cached PyQt6-6.4.2.tar.gz (1.0 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
  ╰─> [22 lines of output]
      Traceback (most recent call last):
        File "/usr/local/lib/python3.9/dist-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/usr/local/lib/python3.9/dist-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/usr/local/lib/python3.9/dist-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 152, in prepare_metadata_for_build_wheel
          whl_basename = backend.build_wheel(metadata_directory, config_settings)
        File "/tmp/pip-build-env-rtbrazp0/overlay/lib/python3.9/site-packages/sipbuild/api.py", line 46, in build_wheel
          project = AbstractProject.bootstrap('wheel',
        File "/tmp/pip-build-env-rtbrazp0/overlay/lib/python3.9/site-packages/sipbuild/abstract_project.py", line 87, in bootstrap
          project.setup(pyproject, tool, tool_description)
        File "/tmp/pip-build-env-rtbrazp0/overlay/lib/python3.9/site-packages/sipbuild/project.py", line 585, in setup
          self.apply_user_defaults(tool)
        File "project.py", line 65, in apply_user_defaults
          super().apply_user_defaults(tool)
        File "/tmp/pip-build-env-rtbrazp0/overlay/lib/python3.9/site-packages/pyqtbuild/project.py", line 70, in apply_user_defaults
          super().apply_user_defaults(tool)
        File "/tmp/pip-build-env-rtbrazp0/overlay/lib/python3.9/site-packages/sipbuild/project.py", line 236, in apply_user_defaults
          self.builder.apply_user_defaults(tool)
        File "/tmp/pip-build-env-rtbrazp0/overlay/lib/python3.9/site-packages/pyqtbuild/builder.py", line 69, 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.

OS: Raspberry Pi 32 bit (Raspbian GNU/Linux 11 (bullseye)), Kernel 5.15.61-v7+, version of Python 3.9.2, hardware Raspberry Pi 3 Model B Rev 1.2 and Raspberry Pi 4 Model B

Thank you for your help!

UPD: https://www.tal.org/tutorials/building-qt-62-raspberry-pi-raspberry-pi-os


Solution

  • The core reason for has no attribute 'prepare_metadata_for_build_wheel' is that qmake is not in PATH. But after adding qmake to PATH the installation still hangs.

    Here is how I got it to work:

    Install dependencies

    apt install ninja-build libfontconfig1-dev libdbus-1-dev libfreetype6-dev libicu-dev libinput-dev libxkbcommon-dev libsqlite3-dev libssl-dev libpng-dev libjpeg-dev libglib2.0-dev libgles2-mesa-dev libgbm-dev libdrm-dev libx11-dev libxcb1-dev libxext-dev libxi-dev libxcomposite-dev libxcursor-dev libxtst-dev libxrandr-dev libx11-xcb-dev libxext-dev libxfixes-dev libxi-dev libxrender-dev libxcb1-dev libxcb-glx0-dev libxcb-keysyms1-dev libxcb-image0-dev libxcb-shm0-dev libxcb-icccm4-dev libxcb-sync-dev libxcb-xfixes0-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-render-util0-dev libxcb-util0-dev libxcb-xinerama0-dev libxcb-xkb-dev libxkbcommon-dev libxkbcommon-x11-dev libxcb-xinput-dev
    
    

    Im not sure if all are needed.

    Get source

    wget https://download.qt.io/official_releases/qt/6.2/6.2.4/submodules/qtbase-everywhere-src-6.2.4.tar.xz
    

    Build

    tar xf qtbase-everywhere-src-6.2.4.tar.xz
    mkdir qtbase-everywhere-src-6.2.4/build
    cd qtbase-everywhere-src-6.2.4/build
    cmake -G Ninja \
    -DCMAKE_INSTALL_PREFIX=/opt/Qt/6.2.4-armv7l \
    -DQT_FEATURE_opengles2=ON \
    -DQT_FEATURE_opengles3=ON \
    -DQT_FEATURE_kms=ON \
    -DQT_AVOID_CMAKE_ARCHIVING_API=ON ..
    cmake --build . --parallel 4
    

    Install Qt6

    cmake --install .
    

    Get pyqt6 source

    cd
    wget https://files.pythonhosted.org/packages/28/01/9e4b91cb0c1023934b1dc654c5bbfc29cbabcbf6092f936b74aee46dd637/PyQt6-6.5.0.tar.gz
    tar -xzf PyQt6-6.5.0.tar.gz
    

    Install build dependencies

    Building with pip doesn't work so you need do build with sip

    pip install PyQt-builder # will also install sip
    

    Build

    For some reason -latomic doesn't get passed properly to g++, so you will have to set QMAKE_LIBS_LIBATOMIC manually.

    export PATH="$PATH:/opt/Qt/6.2.4-armv7l/bin"
    cd PyQt6-6.5.0
    sip-wheel --confirm-license --verbose --qmake-setting 'QMAKE_LIBS_LIBATOMIC = -latomic'
    

    Install pyqt6

    pip install ./PyQt6-6.5.0-cp37-abi3-manylinux_2_28_armv7l.whl