For those of us who eagerly await the release the proper armhf compatible python3 package, in the meantime, this is how I’ve compiled python3 to run on my Kindle Scribe 5.17.0.1 (armhf)
Please consider this just as a notebook in progress, most of the things may/will not work, I followed the suggestion and tried the
Quote:
Originally Posted by NiLuJe
just respin the package w/ KindleTool yourself.
|
By the way thanks to the eminent programmer/s involved in Koxtoolchain, KindleTool and all the packages in this thread.
Dockerfile
Code:
FROM --platform=linux/amd64 debian:bullseye AS amd64-base
RUN apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y \
build-essential autoconf automake bison flex gawk \
libtool libtool-bin libncurses-dev \
curl file git gperf help2man texinfo unzip wget
# Python dev deps for --with-build-python
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y \
make libssl-dev zlib1g-dev libbz2-dev libreadline-dev \
libsqlite3-dev llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev liblzma-dev tk-dev libffi-dev
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y \
pkg-config
WORKDIR /root
RUN wget -qO- https://www.python.org/ftp/python/3.11.11/Python-3.11.11.tgz | tar xvz
RUN cp -r Python-3.11.11 Python-3.11.11-armhf
RUN cd Python-3.11.11 && \
./configure --prefix=/usr/local/python-native --enable-optimizations --with-lto --with-computed-gotos --with-system-ffi && \
make -j$(nproc) && \
make install
RUN wget -qO- https://github.com/KindleModding/koxtoolchain/releases/download/2025.01/kindlehf.tar.gz | tar xvz && \
wget -qO- https://github.com/KindleModding/koxtoolchain/raw/27f361f5d5e1b85b6d02978a6b45271a2605019c/refs/x-compile.sh > x-compile.sh
# TO-Discover Where on earth are the contents of ./Kindle/CrossTool/Build_KHF sysroot?? "./gen-tc.sh kindlehf" doesn't seem to gather them, and they are not in kindlehf.tar.gz either.
RUN mkdir -p /mnt/us/python3
RUN echo '#!/bin/bash\n\
\n\
set -a\n\
HOME=/root source /root/x-compile.sh kindlehf env bare\n\
set +a\n\
\n\
export CC=$CROSS_TC-gcc\n\
export CXX=$CROSS_TC-g++\n\
export STRIP=$CROSS_TC-strip\n\
export AR=$CROSS_TC-gcc-ar\n\
export RANLIB=$CROSS_TC-gcc-ranlib\n\
export LD=$CROSS_TC-ld\n\
export READELF=$CROSS_TC-readelf\n\
export SYSROOT=/mnt/us/python3\n\
export X_TOOLS_SYSROOT=/root/x-tools/arm-kindlehf-linux-gnueabihf/arm-kindlehf-linux-gnueabihf/sysroot\n\
export CFLAGS="-I$SYSROOT/usr/include -I$X_TOOLS_SYSROOT/usr/include"\n\
export CPPFLAGS="-I$SYSROOT/usr/include -I$X_TOOLS_SYSROOT/usr/include"\n\
export LDFLAGS="-L$SYSROOT/lib -L$SYSROOT/usr/lib -L$X_TOOLS_SYSROOT/lib -L$X_TOOLS_SYSROOT/usr/lib -Wl,-rpath=/mnt/us/python3/usr/lib -Wl,-rpath-link=$SYSROOT/lib:$SYSROOT/usr/lib:$X_TOOLS_SYSROOT/lib:$X_TOOLS_SYSROOT/usr/lib"\n\
export PKG_CONFIG_SYSROOT_DIR="$SYSROOT"\n\
export PKG_CONFIG_PATH="$SYSROOT/usr/lib/pkgconfig"\n\
' > /root/exec && chmod +x /root/exec
RUN wget -qO- https://github.com/madler/zlib/archive/refs/tags/v1.3.1.tar.gz | tar xvz
RUN cd zlib-1.3.1 && \
bash -c "source /root/exec && \
./configure --prefix=/usr && \
make -j$(nproc) && \
make install DESTDIR=\$SYSROOT"
RUN wget -qO- https://github.com/libffi/libffi/releases/download/v3.4.6/libffi-3.4.6.tar.gz | tar xvz
RUN cd libffi-3.4.6 && \
bash -c "source /root/exec && \
./configure --prefix=/usr --host=arm-linux-gnueabihf --build=x86_64-pc-linux-gnu && \
make -j$(nproc) && \
make install DESTDIR=\$SYSROOT"
RUN wget -qO- https://github.com/openssl/openssl/archive/refs/tags/OpenSSL_1_1_1w.tar.gz | tar xvz
RUN cd openssl-OpenSSL_1_1_1w && \
bash -c "source /root/exec && \
./Configure linux-armv4 --prefix=/usr --openssldir=/etc/ssl -DOPENSSL_PIC -DOTHER_LIBS=atomic -lpthread -latomic && \
make -j$(nproc) && \
make install DESTDIR=\$SYSROOT"
RUN wget -qO- https://www.sqlite.org/2024/sqlite-autoconf-3450100.tar.gz | tar xvz
RUN cd sqlite-autoconf-3450100 && \
bash -c "source /root/exec && \
./configure --prefix=/usr --host=arm-linux-gnueabihf --build=x86_64-pc-linux-gnu && \
make -j$(nproc) && \
make install DESTDIR=\$SYSROOT"
RUN wget -qO- https://ftp.gnu.org/gnu/ncurses/ncurses-6.4.tar.gz | tar xvz
RUN cd ncurses-6.4 && \
bash -c "source /root/exec && \
./configure --prefix=/usr --host=arm-linux-gnueabihf --build=x86_64-pc-linux-gnu --with-shared --disable-stripping && \
make -j$(nproc) && \
make install DESTDIR=\$SYSROOT"
RUN cd Python-3.11.11-armhf && \
bash -c "source /root/exec && \
./configure --prefix=/usr --host=arm-linux-gnueabihf --build=x86_64-pc-linux-gnu --with-build-python=/usr/local/python-native/bin/python3.11 --enable-shared --enable-optimizations --enable-loadable-sqlite-extensions --with-lto --with-computed-gotos --with-system-ffi --with-ensurepip=install --disable-ipv6 --disable-test-modules ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no && \
make -j$(nproc) && \
make install DESTDIR=\$SYSROOT"
Next, I built the image and copied the python3 sysroot to the device:
Code:
docker buildx build -t kterm_kindle .
docker run --rm -it -v $(pwd):/project kterm_kindle bash -c "tar -czvf /project/python3.tar.gz -C /mnt/us python3"
scp python3.tar.gz root@192.168.1.101:/mnt/us
On the Kindle extracted the python3 sysroot:
Code:
[root@kindle us]# tar -xvf python3.tar.gz -C /mnt/us/
Then running python3 and pip (It is necessary to use the full path or modify $PATH):
Code:
[root@kindle us]# /mnt/us/python3/usr/bin/python3.11 -m ensurepip
[root@kindle us]# /mnt/us/python3/usr/bin/python3.11 -m pip install requests
[root@kindle us]# /mnt/us/python3/usr/bin/python3.11
Python 3.11.11 (main, Jan 29 2025, 20:15:57) [GCC 14.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> r = requests.get('https://httpbin.org/basic-auth/user/pass', auth=('user', 'pass'))
>>> r.status_code
200
>>>
Of course only packages with a compatible built distribution (.whl) available will/may work.
Note: all the “docker” commands were run on MacOS, for linux it may be necessary to adapt them.