Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

python binary?

1 view
Skip to first unread message

Ulli Horlacher

unread,
Apr 18, 2022, 5:47:07 AM4/18/22
to
Ich hab
https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp
installiert.
Auf
https://github.com/yt-dlp/yt-dlp#release-files
steht:
"Platform-independant binary. Needs Python (recommended for Linux/BSD)"

Angeschaut:

root@juhu:/usr/local/bin# file yt-dlp
yt-dlp: a /usr/bin/env python3 script executable (binary data)

root@juhu:/usr/local/bin# fhexdump yt-dlp | head
00000000:23 21 2F 75 73 72 2F 62 69 6E 2F 65 6E 76 20 70 79 74 68 6F
0:# ! / u s r / b i n / e n v p y t h o
00000014:6E 33 0A 50 4B 03 04 14 00 00 00 08 00 20 08 21 28 3C 8D 42
20:n 3 \n P K · · · · · · · · · ! ( < · B
00000028:90 E4 B0 00 00 0B D4 02 00 13 00 1C 00 79 74 5F 64 6C 70 2F
40:· ä ° · · · Ô · · · · · · y t _ d l p /
0000003C:59 6F 75 74 75 62 65 44 4C 2E 70 79 55 54 09 00 03 CC 51 6D
60:Y o u t u b e D L . p y U T \t · · Ì Q m
00000050:38 CC 51 6D 38 75 78 0B 00 01 04 E9 03 00 00 04 79 00 00 00
80:8 Ì Q m 8 u x · · · · é · · · · y · · ·

Was ist das fuer ein Binaerformat, wie erzeugt? Compiler?

--
Ullrich Horlacher Server und Virtualisierung
Rechenzentrum TIK
Universitaet Stuttgart E-Mail: horl...@tik.uni-stuttgart.de
Allmandring 30a Tel: ++49-711-68565868
70569 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/

Sven Hartge

unread,
Apr 18, 2022, 7:57:36 AM4/18/22
to
Ulli Horlacher <fram...@rus.uni-stuttgart.de> wrote:
> Ich hab
> https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp
> installiert.
> Auf
> https://github.com/yt-dlp/yt-dlp#release-files
> steht:
> "Platform-independant binary. Needs Python (recommended for Linux/BSD)"

> Angeschaut:

> root@juhu:/usr/local/bin# file yt-dlp
> yt-dlp: a /usr/bin/env python3 script executable (binary data)

> Was ist das fuer ein Binaerformat, wie erzeugt? Compiler?

Das ist ein ZIP-File mit einem Python-SheBang davor. Siehe
https://github.com/yt-dlp/yt-dlp/blob/43cc91ad759d3950c99a905f0ee4937cade10e5c/Makefile#L62

yt-dlp: yt_dlp/*.py yt_dlp/*/*.py
mkdir -p zip
for d in yt_dlp yt_dlp/downloader yt_dlp/extractor yt_dlp/postprocessor ; do \
mkdir -p zip/$$d ;\
cp -pPR $$d/*.py zip/$$d/ ;\
done
touch -t 200001010101 zip/yt_dlp/*.py zip/yt_dlp/*/*.py
mv zip/yt_dlp/__main__.py zip/
cd zip ; zip -q ../yt-dlp yt_dlp/*.py yt_dlp/*/*.py __main__.py
rm -rf zip
echo '#!$(PYTHON)' > yt-dlp
cat yt-dlp.zip >> yt-dlp
rm yt-dlp.zip
chmod a+x yt-dlp

Also einfach die einzelnen Python-Dateien zusammen zippen und den
SheBand davor packen und der Python-Interpreter macht automatisch das
richtige.

Vergleichbar mir einer JAR-Datei.



--
Sigmentation fault. Core dumped.

Christian Weisgerber

unread,
Apr 18, 2022, 9:30:06 AM4/18/22
to
On 2022-04-18, Ulli Horlacher <fram...@rus.uni-stuttgart.de> wrote:

> root@juhu:/usr/local/bin# file yt-dlp
> yt-dlp: a /usr/bin/env python3 script executable (binary data)
>
> Was ist das fuer ein Binaerformat, wie erzeugt? Compiler?

Python-Programmtext (*.py) kann als Optimierung zu Bytecode (*.pyc)
compiliert werden. Das ist banaler Bestandteil der Referenz-
implementierung.

Ein „locate .pyc“ sollte schon eine große Anzahl an Beispielen in
der python-Basisinstallation zu Tage fördern.

--
Christian "naddy" Weisgerber na...@mips.inka.de

Sven Hartge

unread,
Apr 18, 2022, 9:48:29 AM4/18/22
to
Generall schon, trifft hier im speziellen nur nicht zu.

yt-dlp ist wirklich nur ein ZIP mit den originalen .py Dateien, zur
einfacheren Verteilung.

Christian Weisgerber

unread,
Apr 18, 2022, 11:30:05 AM4/18/22
to
On 2022-04-18, Sven Hartge <sh-...@svenhartge.de> wrote:

>> root@juhu:/usr/local/bin# file yt-dlp
>> yt-dlp: a /usr/bin/env python3 script executable (binary data)
>
>> Was ist das fuer ein Binaerformat, wie erzeugt? Compiler?
>
> Das ist ein ZIP-File mit einem Python-SheBang davor.

Oh, in der Tat:

$ unzip -l /usr/local/bin/yt-dlp | head
Archive: /usr/local/bin/yt-dlp
Length Date Time Name
-------- ---- ---- ----
183709 01-01-99 01:01 yt_dlp/YoutubeDL.py
37899 01-01-99 01:01 yt_dlp/__init__.py
21157 01-01-99 01:01 yt_dlp/aes.py
3128 01-01-99 01:01 yt_dlp/cache.py
9275 01-01-99 01:01 yt_dlp/compat.py
37791 01-01-99 01:01 yt_dlp/cookies.py
21594 01-01-99 01:01 yt_dlp/jsinterp.py

Ulli Horlacher

unread,
Apr 18, 2022, 6:29:13 PM4/18/22
to
Sven Hartge <sh-...@svenhartge.de> wrote:

> https://github.com/yt-dlp/yt-dlp/blob/43cc91ad759d3950c99a905f0ee4937cade10e5c/Makefile#L62
>
> yt-dlp: yt_dlp/*.py yt_dlp/*/*.py
> mkdir -p zip
> for d in yt_dlp yt_dlp/downloader yt_dlp/extractor yt_dlp/postprocessor ; do \
> mkdir -p zip/$$d ;\
> cp -pPR $$d/*.py zip/$$d/ ;\
> done
> touch -t 200001010101 zip/yt_dlp/*.py zip/yt_dlp/*/*.py
> mv zip/yt_dlp/__main__.py zip/
> cd zip ; zip -q ../yt-dlp yt_dlp/*.py yt_dlp/*/*.py __main__.py
> rm -rf zip
> echo '#!$(PYTHON)' > yt-dlp
> cat yt-dlp.zip >> yt-dlp
> rm yt-dlp.zip
> chmod a+x yt-dlp

Ich geb zu, ich hab seit 20 Jahren keine makefiles mehr erstellt.
Ich dachte immer, die make execute Zeilen waeren normaler shell-Code.
Was macht da $$d? Wieso nicht $d?
Und wie(so) wird '#!$(PYTHON)' expandiert?
Ich haette da "#!$PYTHON" erwartet.



> Also einfach die einzelnen Python-Dateien zusammen zippen und den
> SheBand davor packen und der Python-Interpreter macht automatisch das
> richtige.

Interessant. Das hab ich noch nirgends gesehen. Wo kann man das nachlesen?

Peter J. Holzer

unread,
Apr 18, 2022, 7:42:14 PM4/18/22
to
On 2022-04-18 22:29, Ulli Horlacher <fram...@rus.uni-stuttgart.de> wrote:
> Sven Hartge <sh-...@svenhartge.de> wrote:
>
>> https://github.com/yt-dlp/yt-dlp/blob/43cc91ad759d3950c99a905f0ee4937cade10e5c/Makefile#L62
>>
>> yt-dlp: yt_dlp/*.py yt_dlp/*/*.py
>> mkdir -p zip
>> for d in yt_dlp yt_dlp/downloader yt_dlp/extractor yt_dlp/postprocessor ; do \
>> mkdir -p zip/$$d ;\
>> cp -pPR $$d/*.py zip/$$d/ ;\
>> done
[...]
>> echo '#!$(PYTHON)' > yt-dlp
[...]
>
> Ich geb zu, ich hab seit 20 Jahren keine makefiles mehr erstellt.
> Ich dachte immer, die make execute Zeilen waeren normaler shell-Code.
> Was macht da $$d? Wieso nicht $d?

Weil $ auch von Make zur Variablensubstitution verwendet wird. Damit das
$ bei der Shell ankommt, muss man es escapen (durch Verdopplung)

> Und wie(so) wird '#!$(PYTHON)' expandiert?
> Ich haette da "#!$PYTHON" erwartet.

Wenn der Variablenname mehr als ein Zeichen hat, muss man ihn in
Klammern einschließen.


>> Also einfach die einzelnen Python-Dateien zusammen zippen und den
>> SheBand davor packen und der Python-Interpreter macht automatisch das
>> richtige.
>
> Interessant. Das hab ich noch nirgends gesehen. Wo kann man das nachlesen?

https://docs.python.org/3/using/cmdline.html#interface-options

| <script>
|
| Execute the Python code contained in script, which must be a
| filesystem path (absolute or relative) referring to either a Python
| file, a directory containing a __main__.py file, or a zipfile
| containing a __main__.py file.

hp

Helmut Waitzmann

unread,
Apr 19, 2022, 4:38:57 PM4/19/22
to
Ulli Horlacher <fram...@rus.uni-stuttgart.de>:

>Ich geb zu, ich hab seit 20 Jahren keine makefiles mehr erstellt.
>Ich dachte immer, die make execute Zeilen waeren normaler
>shell-Code.

Erst dann, wenn sie durch den Make‐Präprozessor gelaufen sind, sind
sie Shell‐Code.  Wie der Präprozessor funktioniert, sollte im
Handbuch des verwendeten Make‐Programms zu lesen sein.  (Leider gibt
der POSIX‐Standard für Make ziemlich wenig her.  Daher muss man bei
den verschiedenen Make‐Implementierungen mit zu einander
inkompatiblen Erweiterungen des POSIX‐Standards rechnen.)

Mit dem Make‐Präprozessor haben auch die von dir beobachteten
Effekte zu tun:

>Was macht da $$d? Wieso nicht $d?
>

«$d» würde die (hypothetische) Make‐Präprozessor‐Variable «d»
expandieren.  Das ist hier aber nicht gewünscht.

«$$d» wird vom Make‐Präprozessor in «$d» umgesetzt:  Zwei vom
Make‐Präprozessor erkannte aufeinanderfolgende «$» setzt er als ein
einzelnes «$» in die Shell‐Kommandozeile, die er erstellt.  Die vom
Make‐Präprozessor erstellte Shell‐Kommandozeile enthält also den Text
«$d».

>Und wie(so) wird '#!$(PYTHON)' expandiert?
>

Auch da siehst du wieder den Make‐Präprozessor am Werk:  Er ersetzt
im Text «'#!$(PYTHON)'» den Teil «$(PYTHON)» durch den Wert der
Make‐Präprozessor‐Variablen «PYTHON».  Dadurch entsteht in der von
ihm erstellten Shell‐Kommandozeile der Text «'#!/usr/bin/python3'».

Du fragst «wieso»?  Vermutlich vermutest du, der Apostroph habe für
den Make‐Präprozessor eine Sonderbedeutung ähnlich wie im Shell,
richtig?  Das ist nicht der Fall:  Ein Apostroph wird vom
Make‐Präprozessor unverändert an die Shell‐Kommandozeile
weitergereicht.
0 new messages