I have a container with python:3.6-alpine
kernel, I have a problem to install the pyzmq with pip on this:
Dockerfile:
FROM python:3.6-alpine
RUN mkdir /code
RUN apk add vim
WORKDIR /
ADD . /code
docker-compose.yml:
version: '3'
services:
battery_monitoring:
build: .
image: bm:1.0.0
container_name: battery_monitoring
restart: unless-stopped
volumes:
- .:/code
tty: true
When I install several Python libraries on this container I haven't any problem, but in pyzmq library, there is an error:
Procedure:
$ docker-compose build
$ docker-compose up -d
$ docker exec -it <This-container-ID> sh
In the container:
pip install pyserial
pip install easydict
Above commands installed as well, but in pyzmq installation, I encountered to the following error:
pip install pyzmq
A part of the result:
----------------------------------------
Command "/usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-545my4q5/pyzmq/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-nbtsgz0b/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-545my4q5/pyzmq/
[NOTE]:
pip -V
pip 18.0 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
which pip
/usr/local/bin/pip
I haven't any problem with FROM python:3.6-slim
instead of FROM python:3.6-alpine
Check if this works better with python 3.7, as mentioned in zeromq/pyzmq issue 1050
Using
py3-zmq
packageFrom my experience,
python:3.6-alpine
is not well suited for installing packages with C extensions because of missing Python headers. Thealpine
images already offer a Python 3.6 distribution and also a precompiledpyzmq
package, so it's already sufficient to do:Check:
This is the easiest and most reliable way to install
pyzmq
in an Alpine container.Building from source with
pip install
Alpine is not manylinux1-compatible, so any package containing C extensions must be built from source. This means you have to install the build tools first. Again, I'd use
alpine
image instead ofpython:3.6-alpine
:Check:
If you insist on
python:3.6-alpine
Beware that
python:3.6-alpine
does not install Python viaapk
, it has Python built from source and located under/usr/local
. So when you inherit frompython:3.6-alpine
, installpython3-dev
and runpip install pyzmq
, you'll end up with buildingpyzmq
for Python 3.6.6 (coming frompython:3.6-alpine
) using header files from Python 3.6.4 (coming fromapk add python3-dev
). In general, this shouldn't be an issue (header files are incompatible only between major Python releases), but may become an issue in case the header files were adapted by the distro maintainer.Edit: exact steps to reproduce, with log