Native Dependencies beim Installieren über pip

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
John Johnson
User
Beiträge: 2
Registriert: Donnerstag 12. Mai 2022, 18:09

Hallo zusammen,

ich stelle mir die Frage, ob und wie bei der Installation eines Paketes über pip automatisch native Dependencies installiert werden.
Nehmen wir zum Beispiel matplotlib, bei der Installation in Ubuntu über apt werden diverse Nicht-Python-Dependencies installiert.
Dies ist der Output von

Code: Alles auswählen

apt show python3-matplotlib
apt show python3-matplotlib
Package: python3-matplotlib
Version: 3.1.2-1ubuntu4
Priority: optional
Section: universe/python
Source: matplotlib
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Sandro Tosi <morph@debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 13,7 MB
Depends: python3-dateutil, python-matplotlib-data (>= 3.1.2-1ubuntu4), python3-pyparsing (>= 1.5.6), python3-six (>= 1.4), libjs-jquery, libjs-jquery-ui, python3-numpy (>= 1:1.16.0~rc1), python3-numpy-abi9, python3 (<< 3.9), python3 (>= 3.8~), python3-cycler (>= 0.10.0), python3-kiwisolver, python3:any, libc6 (>= 2.29), libfreetype6 (>= 2.2.1), libgcc-s1 (>= 3.0), libpng16-16 (>= 1.6.2-1), libstdc++6 (>= 5.2)
Recommends: python3-pil, python3-tk
Suggests: dvipng, ffmpeg, gir1.2-gtk-3.0, ghostscript, inkscape, ipython3, librsvg2-common, python-matplotlib-doc, python3-cairocffi, python3-gi, python3-gi-cairo, python3-gobject, python3-nose, python3-pyqt5, python3-scipy, python3-sip, python3-tornado, texlive-extra-utils, texlive-latex-extra, ttf-staypuft
Enhances: ipython3
Homepage: http://matplotlib.org/
Task: ubuntustudio-video
Download-Size: 4.459 kB
APT-Manual-Installed: no
APT-Sources: http://de.archive.ubuntu.com/ubuntu focal/universe amd64 Packages
Description: Python based plotting system in a style similar to Matlab (Python 3)
Matplotlib is a pure Python plotting library designed to bring
publication quality plotting to Python with a syntax familiar to
Matlab users. All of the plotting commands in the pylab interface can
be accessed either via a functional interface familiar to Matlab
users or an object oriented interface familiar to Python users.
.
This package contains the Python 3 version of matplotlib.
Wie hier zu sehen ist, wird unter anderem libjs-jquery installiert.
Ist dies beim pip-Äquivalent auch der Fall und wenn ja, wie wird das realisiert?

Viele Grüße,
euer Johnny :ugeek:
Benutzeravatar
sparrow
User
Beiträge: 4164
Registriert: Freitag 17. April 2009, 10:28

jquery ist jetzt nichts, was ich als "native dependeny" sehen würde, wenn ich ehrlich bin.
Das Projekt hat eine ausführliche Intallationsanleitung und weist auch auf Abhängigkeiten hin. Sowohl auf benötigte als auch auf optionale. Ich sehe da erst einmal kein jquery.

Ein Blick in das Repository zeigt, dass jquery in Version 3.2 spätestens 3.3 entfernt wurden. Wenn du dir also das Projekt vor dieser Version anschaust, solltest du fündig werden.

Edit: Ein guter Einstieg in das Thema ist wie immer die Dokumentation.
narpfel
User
Beiträge: 643
Registriert: Freitag 20. Oktober 2017, 16:10

Wenn man sich `debian/rules` aus dem Source-Paket anguckt, findet man ab Zeile 133:

Code: Alles auswählen

	-rm $(CURDIR)/debian/$(p3)/usr/lib/python3/dist-packages/matplotlib/backends/web_backend/jquery/js/jquery-1.7.1.min.js
	-rm $(CURDIR)/debian/$(p3)/usr/lib/python3/dist-packages/matplotlib/backends/web_backend/jquery/js/jquery-ui.min.js
	-rm $(CURDIR)/debian/$(p3)/usr/lib/python3/dist-packages/matplotlib/backends/web_backend/jquery/css/themes/base/jquery-ui.min.css
Da wird also beim Bauen vom Debian-Paket extra `jquery` entfernt, damit es als Abhängigkeit über `apt` genutzt wird.

Wenn man ein wenig im Matplotlib-Repo sucht (`git grep jquery` und `git log -G jquery`), findet man, dass die jquery bis vor ein paar Versionen einfach per Copy-Paste in ihrem Repo hatten und dass das dementsprechend in den Wheels und Source-Paketen enthalten war. Mit Version 3.3.0 ist das dann überflüssig geworden (PR hier) und entfernt worden. Das ist anscheinend bei Debian einfach noch nicht angekommen, sodass die Abhängigkeit jetzt unnötig ist.

Allgemein gilt, dass Python-Pakete, die per `pip` installiert werden, alles Mögliche enthalten können. Nativen Code, Programme, Python-Code, HTML- und CSS-Dateien, ...

Für die restlichen nativen Abhängigkeiten:

Code: Alles auswählen

$ cd /tmp
$ virtualenv venv
$ . venv/bin/activate
$ pip install matplotlib
$ fd '.so(\.\d+)*$' venv/lib/ --print0 | xargs -0 ldd | rg -o '^\s+[/\w\.-]+( => [^(]+)' | sort | uniq
        libc.so.6 => /usr/lib/libc.so.6
        libdl.so.2 => /usr/lib/libdl.so.2
        libfreetype-21ca3c10.so.6.18.2 => not found
        libfreetype-21ca3c10.so.6.18.2 => /tmp/venv/lib/python3.10/site-packages/PIL/../Pillow.libs/libfreetype-21ca3c10.so.6.18.2
        libgcc_s.so.1 => /usr/lib/libgcc_s.so.1
        libgfortran-040039e1.so.5.0.0 => not found
        libgfortran-040039e1.so.5.0.0 => /tmp/venv/lib/python3.10/site-packages/numpy/core/../../numpy.libs/libgfortran-040039e1.so.5.0.0
        libgfortran-040039e1.so.5.0.0 => /tmp/venv/lib/python3.10/site-packages/numpy/linalg/../../numpy.libs/libgfortran-040039e1.so.5.0.0
        libharfbuzz-3e5a9845.so.0.40200.0 => /tmp/venv/lib/python3.10/site-packages/PIL/../Pillow.libs/libharfbuzz-3e5a9845.so.0.40200.0
        libjpeg-dffd3595.so.62.3.0 => not found
        libjpeg-dffd3595.so.62.3.0 => /tmp/venv/lib/python3.10/site-packages/PIL/../Pillow.libs/libjpeg-dffd3595.so.62.3.0
        liblcms2-1e643a89.so.2.0.13 => /tmp/venv/lib/python3.10/site-packages/PIL/../Pillow.libs/liblcms2-1e643a89.so.2.0.13
        liblzma-d540a118.so.5.2.5 => not found
        liblzma-d540a118.so.5.2.5 => /tmp/venv/lib/python3.10/site-packages/PIL/../Pillow.libs/liblzma-d540a118.so.5.2.5
        libm.so.6 => /usr/lib/libm.so.6
        libopenblas64_p-r0-2f7c42d4.3.18.so => /tmp/venv/lib/python3.10/site-packages/numpy/core/../../numpy.libs/libopenblas64_p-r0-2f7c42d4.3.18.so
        libopenblas64_p-r0-2f7c42d4.3.18.so => /tmp/venv/lib/python3.10/site-packages/numpy/linalg/../../numpy.libs/libopenblas64_p-r0-2f7c42d4.3.18.so
        libopenjp2-430a98fc.so.2.4.0 => /tmp/venv/lib/python3.10/site-packages/PIL/../Pillow.libs/libopenjp2-430a98fc.so.2.4.0
        libpng16-52f22300.so.16.37.0 => not found
        libpng16-52f22300.so.16.37.0 => /tmp/venv/lib/python3.10/site-packages/PIL/../Pillow.libs/libpng16-52f22300.so.16.37.0
        libpthread.so.0 => /usr/lib/libpthread.so.0
        libquadmath-96973f99.so.0.0.0 => not found
        libquadmath-96973f99.so.0.0.0 => /tmp/venv/lib/python3.10/site-packages/numpy/core/../../numpy.libs/libquadmath-96973f99.so.0.0.0
        libquadmath-96973f99.so.0.0.0 => /tmp/venv/lib/python3.10/site-packages/numpy/linalg/../../numpy.libs/libquadmath-96973f99.so.0.0.0
        libtiff-d0580107.so.5.7.0 => /tmp/venv/lib/python3.10/site-packages/PIL/../Pillow.libs/libtiff-d0580107.so.5.7.0
        libwebp-8efe125f.so.7.1.3 => not found
        libwebp-8efe125f.so.7.1.3 => /tmp/venv/lib/python3.10/site-packages/PIL/../Pillow.libs/libwebp-8efe125f.so.7.1.3
        libwebpdemux-016472e8.so.2.0.9 => /tmp/venv/lib/python3.10/site-packages/PIL/../Pillow.libs/libwebpdemux-016472e8.so.2.0.9
        libwebpmux-5c00cf3e.so.3.0.8 => /tmp/venv/lib/python3.10/site-packages/PIL/../Pillow.libs/libwebpmux-5c00cf3e.so.3.0.8
        libXau-00ec42fe.so.6.0.0 => not found
        libXau-00ec42fe.so.6.0.0 => /tmp/venv/lib/python3.10/site-packages/PIL/../Pillow.libs/libXau-00ec42fe.so.6.0.0
        libxcb-1122e22b.so.1.1.0 => /tmp/venv/lib/python3.10/site-packages/PIL/../Pillow.libs/libxcb-1122e22b.so.1.1.0
        libz.so.1 => /usr/lib/libz.so.1
Wie du siehst: Sehr viele shared libraries (== nativer Code, in C oder Fortran oder Rust oder ... geschrieben), die untereinander sehr viele Abhängigkeiten haben. Aber das allermeiste sind Abhängigkeiten innerhalb der venv, also mitgelieferte. Die einzigen Abhängigkeiten, die nicht mitgeliefert werden, sind Sachen wie `libc` und `libpthread`, die auf jedem Linux-System immer existieren. Man kann zum Beispiel sehen, dass libpng16 und libharfbuzz in die venv installiert wurden, allerdings auch in den Abhängigkeiten des Debian-Pakets stehen (libharfbuzz transitiv via libfreetype6).

Wie das realisiert wird? Die Entwickler von matplotlib bauen für jede Plattform und jede Python-Version ein eigenes Wheel (hier ist die Liste), das jeweils alle nativen Abhängigkeiten zur Plattform passend kompiliert enthält. Und wenn es kein passendes Wheel gibt (weil man eine exotische Architektur wie S390x oder so benutzt), muss man sich selbst darum kümmern, dass die passenden Abhängigkeiten auf dem System installiert sind und `pip` wählt das Source-Paket aus und kompiliert beim Installieren alles nötige automatisch im Hintergrund.
John Johnson
User
Beiträge: 2
Registriert: Donnerstag 12. Mai 2022, 18:09

Vielen Dank für eure Antworten!
Ich glaube jetzt ist es etwas klarer geworden,
Grüße euer Johnny :ugeek:
Antworten