How can I build a Python package that uses UV and pyqt5?

When I try to run an application that depends on pyqt5, I get an error.

Traceback (most recent call last):
  File "/home/maddy/.local/share/mise/installs/pipx-git-https-github-com-maddy-guthridge-pyqtprotractor-git/master/bin/pyqtprotractor", line 6, in <module>
    from pyqtprotractor import main
  File "/home/maddy/.local/share/mise/installs/pipx-git-https-github-com-maddy-guthridge-pyqtprotractor-git/master/pyqtprotractor/lib/python3.14/site-packages/pyqtprotractor/__init__.py", line 25, in <module>
    from PyQt5.Qt import Qt, QApplication, QWidget
ImportError: cannot import name 'Qt' from 'PyQt5.Qt' (/home/maddy/.local/share/mise/installs/pipx-git-https-github-com-maddy-guthridge-pyqtprotractor-git/master/pyqtprotractor/lib/python3.14/site-packages/PyQt5/Qt.abi3.so)

However, when I try to set up a nix shell using uv2nix, I get this horrific build error:

error: builder for '/nix/store/7yq54fkclm0zljphj0li6hdyja2k11fs-pyqt5-5.15.11.drv' failed with exit code 1;
       last 25 log lines:
       > error: auto-patchelf could not satisfy dependency libQt5Qml.so.5 wanted by /nix/store/4b0ra527svdaxgh6w4sddip27lsx52md-pyqt5-5.15.11/lib/python3.12/site-packages/PyQt5/QtQml.abi3.so
       > error: auto-patchelf could not satisfy dependency libQt5Network.so.5 wanted by /nix/store/4b0ra527svdaxgh6w4sddip27lsx52md-pyqt5-5.15.11/lib/python3.12/site-packages/PyQt5/QtQml.abi3.so
       > error: auto-patchelf could not satisfy dependency libQt5Core.so.5 wanted by /nix/store/4b0ra527svdaxgh6w4sddip27lsx52md-pyqt5-5.15.11/lib/python3.12/site-packages/PyQt5/QtQml.abi3.so
       > error: auto-patchelf could not satisfy dependency libQt5MultimediaWidgets.so.5 wanted by /nix/store/4b0ra527svdaxgh6w4sddip27lsx52md-pyqt5-5.15.11/lib/python3.12/site-packages/PyQt5/QtMultimediaWidgets.abi3.so
       > error: auto-patchelf could not satisfy dependency libQt5Multimedia.so.5 wanted by /nix/store/4b0ra527svdaxgh6w4sddip27lsx52md-pyqt5-5.15.11/lib/python3.12/site-packages/PyQt5/QtMultimediaWidgets.abi3.so
       > error: auto-patchelf could not satisfy dependency libQt5Widgets.so.5 wanted by /nix/store/4b0ra527svdaxgh6w4sddip27lsx52md-pyqt5-5.15.11/lib/python3.12/site-packages/PyQt5/QtMultimediaWidgets.abi3.so
       > error: auto-patchelf could not satisfy dependency libQt5Gui.so.5 wanted by /nix/store/4b0ra527svdaxgh6w4sddip27lsx52md-pyqt5-5.15.11/lib/python3.12/site-packages/PyQt5/QtMultimediaWidgets.abi3.so
       > error: auto-patchelf could not satisfy dependency libQt5Network.so.5 wanted by /nix/store/4b0ra527svdaxgh6w4sddip27lsx52md-pyqt5-5.15.11/lib/python3.12/site-packages/PyQt5/QtMultimediaWidgets.abi3.so
       > error: auto-patchelf could not satisfy dependency libQt5Core.so.5 wanted by /nix/store/4b0ra527svdaxgh6w4sddip27lsx52md-pyqt5-5.15.11/lib/python3.12/site-packages/PyQt5/QtMultimediaWidgets.abi3.so
       > error: auto-patchelf could not satisfy dependency libQt5Location.so.5 wanted by /nix/store/4b0ra527svdaxgh6w4sddip27lsx52md-pyqt5-5.15.11/lib/python3.12/site-packages/PyQt5/QtLocation.abi3.so
       > error: auto-patchelf could not satisfy dependency libQt5PositioningQuick.so.5 wanted by /nix/store/4b0ra527svdaxgh6w4sddip27lsx52md-pyqt5-5.15.11/lib/python3.12/site-packages/PyQt5/QtLocation.abi3.so
       > error: auto-patchelf could not satisfy dependency libQt5Quick.so.5 wanted by /nix/store/4b0ra527svdaxgh6w4sddip27lsx52md-pyqt5-5.15.11/lib/python3.12/site-packages/PyQt5/QtLocation.abi3.so
       > error: auto-patchelf could not satisfy dependency libQt5Gui.so.5 wanted by /nix/store/4b0ra527svdaxgh6w4sddip27lsx52md-pyqt5-5.15.11/lib/python3.12/site-packages/PyQt5/QtLocation.abi3.so
       > error: auto-patchelf could not satisfy dependency libQt5Positioning.so.5 wanted by /nix/store/4b0ra527svdaxgh6w4sddip27lsx52md-pyqt5-5.15.11/lib/python3.12/site-packages/PyQt5/QtLocation.abi3.so
       > error: auto-patchelf could not satisfy dependency libQt5QmlModels.so.5 wanted by /nix/store/4b0ra527svdaxgh6w4sddip27lsx52md-pyqt5-5.15.11/lib/python3.12/site-packages/PyQt5/QtLocation.abi3.so
       > error: auto-patchelf could not satisfy dependency libQt5Qml.so.5 wanted by /nix/store/4b0ra527svdaxgh6w4sddip27lsx52md-pyqt5-5.15.11/lib/python3.12/site-packages/PyQt5/QtLocation.abi3.so
       > error: auto-patchelf could not satisfy dependency libQt5Network.so.5 wanted by /nix/store/4b0ra527svdaxgh6w4sddip27lsx52md-pyqt5-5.15.11/lib/python3.12/site-packages/PyQt5/QtLocation.abi3.so
       > error: auto-patchelf could not satisfy dependency libQt5Core.so.5 wanted by /nix/store/4b0ra527svdaxgh6w4sddip27lsx52md-pyqt5-5.15.11/lib/python3.12/site-packages/PyQt5/QtLocation.abi3.so
       > error: auto-patchelf could not satisfy dependency libQt5Gui.so.5 wanted by /nix/store/4b0ra527svdaxgh6w4sddip27lsx52md-pyqt5-5.15.11/lib/python3.12/site-packages/PyQt5/_QOpenGLFunctions_4_1_Core.abi3.so
       > error: auto-patchelf could not satisfy dependency libQt5Core.so.5 wanted by /nix/store/4b0ra527svdaxgh6w4sddip27lsx52md-pyqt5-5.15.11/lib/python3.12/site-packages/PyQt5/_QOpenGLFunctions_4_1_Core.abi3.so
       > error: auto-patchelf could not satisfy dependency libQt5Gui.so.5 wanted by /nix/store/4b0ra527svdaxgh6w4sddip27lsx52md-pyqt5-5.15.11/lib/python3.12/site-packages/PyQt5/QtBluetooth.abi3.so
       > error: auto-patchelf could not satisfy dependency libQt5Bluetooth.so.5 wanted by /nix/store/4b0ra527svdaxgh6w4sddip27lsx52md-pyqt5-5.15.11/lib/python3.12/site-packages/PyQt5/QtBluetooth.abi3.so
       > error: auto-patchelf could not satisfy dependency libQt5Core.so.5 wanted by /nix/store/4b0ra527svdaxgh6w4sddip27lsx52md-pyqt5-5.15.11/lib/python3.12/site-packages/PyQt5/QtBluetooth.abi3.so
       > auto-patchelf failed to find all the required dependencies.
       > Add the missing dependencies to --libs or use `--ignore-missing="foo.so.1 bar.so etc.so"`.
       For full logs, run:
         nix log /nix/store/7yq54fkclm0zljphj0li6hdyja2k11fs-pyqt5-5.15.11.drv
[2/6/11 built (1 failed), 0.0 MiB DL] building pyqt5-5.15.11 (fixupPhase): Add the missing dependeerror: 1 dependencies of derivation '/nix/store/1882bzm57dhs6g66b0y1x1cqq560lf73-pyqtprotractor-dev-env.drv' failed to build
error: 1 dependencies of derivation '/nix/store/gaqhqs0yhzl5rq9m17alsjkvxi300r51-nix-shell-env.drv' failed to build

When I try to create a Nix shell with the same dependency, I do not get errors.

$ nix-shell -p python3Packages.pyqt5
[nix-shell:~/Source/pyqtprotractor]$ python -c 'import PyQt5'

[nix-shell:~/Source/pyqtprotractor]$

For reference, here is my flake, which is based on the template from uv2nix. pyqtprotractor/flake.nix at master · MaddyGuthridge/pyqtprotractor · GitHub

Update: I have now also tried uv2nix_hammer_overrides which should provide the binaries. I am unsure if I am using it correctly, but it doesn’t seem to be working. I get the same error.

When I update to prefer sdist instead of wheel, I get a different error:

error: builder for '/nix/store/bn8c1m7gr6p00rz5zvfdk6yw15vw3rik-pyqt5-sip-12.17.0.drv' failed with exit code 2;
       last 25 log lines:
       > DEBUG uv 0.7.22
       > DEBUG Checking for Python interpreter at path `/nix/store/jd20rkmqmkfkcvk2wl2lmzz7acq4svlr-python3-3.12.12/bin/python3.12`
       > warning: Ignoring invalid `SSL_CERT_FILE`. File does not exist: /no-cert-file.crt.
       > DEBUG Using request timeout of 30s
       > DEBUG Not using uv build backend direct build of , no pyproject.toml: TOML parse error at line 1, column 1
       >   |
       > 1 | [build-system]
       >   | ^
       > missing field `project`
       >
       > Building wheel...
       > DEBUG Proceeding without build isolation
       > DEBUG Locking the source tree for setuptools
       > DEBUG Acquired lock for `/build/pyqt5_sip-12.17.0`
       > DEBUG Calling `setuptools.build_meta:__legacy__.build_wheel("/build/pyqt5_sip-12.17.0/dist/", {}, None)`
       > Traceback (most recent call last):
       >   File "<string>", line 8, in <module>
       > ModuleNotFoundError: No module named 'setuptools'
       > DEBUG Released lock at `/build/uv-setuptools-827c0b6384a87f15.lock`
       >   x Failed to build `/build/pyqt5_sip-12.17.0`
       >   |-> The build backend returned an error
       >   `-> Call to `setuptools.build_meta:__legacy__.build_wheel` failed (exit
       >       status: 1)
       >       hint: This usually indicates a problem with the package or the build
       >       environment.
       For full logs, run:
         nix log /nix/store/bn8c1m7gr6p00rz5zvfdk6yw15vw3rik-pyqt5-sip-12.17.0.drv
error: 1 dependencies of derivation '/nix/store/y08kj45rs74jhg5sq2vzrdid2yp758f4-pyqtprotractor-dev-env.drv' failed to build
error: 1 dependencies of derivation '/nix/store/8i5nrpz6ppljzcgyfj0vkzsymclfi9w3-nix-shell-env.drv' failed to build

I am still completely lost.

I remember needing to add in my shell.nix

    nativeBuildInputs = [
      libsForQt5.wrapQtAppsHook
    ];

on top of the pyqt5 python dependency

The “horrific build error” is telling you what you need to add to make the package build.

How to override is documented at Overriding - uv2nix.