Here is my Dockerfile:
FROM python:3.11-alpine AS app
RUN apk update && apk add make automake gcc g++ subversion python3-dev gfortran openblas-dev
RUN pip install --upgrade pip
WORKDIR /srv
When I connect to my container and I launch: pip install pyqt5
I got error:
$ pip install pyqt5
Collecting pyqt5
Using cached PyQt5-5.15.9.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
╰─> [25 lines of output]
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
main()
File "/usr/local/lib/python3.11/site-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.11/site-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-z7am47sr/overlay/lib/python3.11/site-packages/sipbuild/api.py", line 46, in build_wheel
project = AbstractProject.bootstrap('wheel',
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/pip-build-env-z7am47sr/overlay/lib/python3.11/site-packages/sipbuild/abstract_project.py", line 87, in bootstrap
project.setup(pyproject, tool, tool_description)
File "/tmp/pip-build-env-z7am47sr/overlay/lib/python3.11/site-packages/sipbuild/project.py", line 586, in setup
self.apply_user_defaults(tool)
File "/tmp/pip-install-p2ogfk1p/pyqt5_97a9414aa7ba410f9715856d348d62b4/project.py", line 68, in apply_user_defaults
super().apply_user_defaults(tool)
File "/tmp/pip-build-env-z7am47sr/overlay/lib/python3.11/site-packages/pyqtbuild/project.py", line 70, in apply_user_defaults
super().apply_user_defaults(tool)
File "/tmp/pip-build-env-z7am47sr/overlay/lib/python3.11/site-packages/sipbuild/project.py", line 237, in apply_user_defaults
self.builder.apply_user_defaults(tool)
File "/tmp/pip-build-env-z7am47sr/overlay/lib/python3.11/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.
hint: See above for details.
How to solve this ?
2
Answers
Try first to add the Qt toolkit, which includes
qmake
.PyQt5 is a set of Python bindings for the Qt libraries, and so it requires some of the Qt tools to be present in order to build correctly.
In Alpine Linux, the Qt tools are typically available in the
qt5-qtbase-dev
package. So you can install it withapk add
.Your Dockerfile would be:
The PyQt5 Pypi project requires that
qmake
can be found (emphasis mine):This can be done by installing e.g.
qt5-qtbase-dev
, potentially together with other packages. Then theqmake
command can be found in the path. (If not, it can be added this way:export PATH=/usr/lib/qt5/bin:$PATH
)So, this should work on the docker container:
(
--no-cache-dir
can save memory usage. But the installation is still quite long and memory intensive.)Honestly, I haven’t managed to install this on my computer with 32GB RAM. The installation step is quite heavy under Alpine Docker and easily leads to OOM. Sadly, there are no pre-compiled sources available (at least not in pypi): https://pypi.org/project/PyQt5/#files
If you do not find wheel files for Alpine from other locations and have not enough RAM to build yourself, I simply recommend not using Alpine Linux. Installation seems much simpler under Ubuntu and other distributions like e.g. Debian Bullseye:
Then
pip install pyqt5
is no problem.Remark: I am not an expert for qmake. So it is possible that there are better ways instead of installation of
qt5-qtbase-dev
. But at least you will end havingqmake
available in the PATH.