Hoffmann
Hoffmann

Reputation: 1082

How can I use python packages from apk in alpine

I installed py3-lxml (and py3-pyldap) and expect python(3) to be able to import the library. But the module was not found. Where am I wrong?

docker run -it python:3-alpine
/ # apk --no-cache --update add py3-lxml py3-pyldap
/ # python3
Python 3.9.6 (default, Jun 29 2021, 19:36:19)
[GCC 10.3.1 20210424] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxml
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'lxml'
>>> import ldap
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'ldap'

Upvotes: 0

Views: 1215

Answers (1)

Hoffmann
Hoffmann

Reputation: 1082

So basically you have two possibilites:

  • either you use the bare alpine image and not only install py3-lxml and py3-pyldap via apk but also python3 itself.
  • or you use python:3-alpine and install the additional packages yourself like this:
apk add --no-cache --virtual .build-deps build-base # only build deps
apk add --no-cache openldap-dev libxml2-dev libxslt-dev # runtime deps
pip install --no-cache-dir -r lxml python-ldap
apk del .build-deps # delete build deps

Or, to quote Jakub, maintainer of alpines py3-pyldap package (huge thanks for the fast response):

Hi, don't mix python installed from whatever source with Alpine python packages. Just replace python:3-alpine with clean alpine:3.14 image and install python3 using apk.

Upvotes: 1

Related Questions