User Tools

Site Tools


projekte:sekwai:crosscompile_python

Crosscompile Python

Hier ist eine kompakte Zusammenfassung des Cross-Compiling von Python auf einem Raspberry Pi 4 für den Pi Zero 2W, mit maximal einer Zeile Erklärung pro Schritt und ohne `&&`-Verkettung der Befehle in den Schritten:

1. Entwicklungsumgebung einrichten ```bash

 sudo apt update
 sudo apt install -y build-essential git crossbuild-essential-armhf python3-dev
 ```
 *Installiert Cross-Compiler und Tools für armhf.*

2. Python-Quellcode herunterladen ```bash

 wget https://www.python.org/ftp/python/3.11.6/Python-3.11.6.tar.xz
 tar -xf Python-3.11.6.tar.xz
 cd Python-3.11.6
 ```
 *Lädt, entpackt und wechselt in Python 3.11.6-Verzeichnis.*

3. Sysroot vom Pi Zero 2W kopieren ```bash

 mkdir ~/pi-zero-sysroot
 rsync -avz pi@<pi-zero-ip>:/lib ~/pi-zero-sysroot
 rsync -avz pi@<pi-zero-ip>:/usr/lib ~/pi-zero-sysroot/usr
 rsync -avz pi@<pi-zero-ip>:/usr/include ~/pi-zero-sysroot/usr
 ```
 *Kopiert Systembibliotheken des Pi Zero 2W.*

4. Python konfigurieren ```bash

 ./configure --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf --build=arm-linux-gnueabihf --prefix=/usr/local --enable-optimizations --with-sysroot=~/pi-zero-sysroot
 ```
 *Konfiguriert Python für Cross-Compilation.*

5. Python kompilieren ```bash

 make -j4
 ```
 *Kompiliert Python mit vier Kernen.*

6. Python installieren ```bash

 make DESTDIR=~/python-armhf install
 ```
 *Installiert Python in temporäres Verzeichnis.*

7. Python auf Pi Zero 2W übertragen ```bash

 tar -czf python-armhf.tar.gz -C ~/python-armhf .
 scp python-armhf.tar.gz pi@<pi-zero-ip>:~/
 ssh pi@<pi-zero-ip>
 sudo tar -xzf python-armhf.tar.gz -C /usr/local
 sudo ldconfig
 ```
 *Komprimiert, überträgt und entpackt Python auf Pi Zero 2W.*

8. Python testen ```bash

 ssh pi@<pi-zero-ip>
 /usr/local/bin/python3 --version
 ```
 *Prüft Python-Version auf Pi Zero 2W.*

Hinweis: Ersetze `<pi-zero-ip>` mit der IP-Adresse des Pi Zero 2W. Beide Geräte müssen im gleichen Netzwerk sein.

projekte/sekwai/crosscompile_python.txt · Last modified: by dominik

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki