tmedicci opened a new pull request, #3487:
URL: https://github.com/apache/nuttx-apps/pull/3487

   ## Summary
   
   Say hello to Python's `pip` on NuttX!
   
   * interpreters/python: Enable using `pip` to install Python packages
     * `pip` is provided as a pre-compiled (pyc) built-in distributed along 
with cpython.
   
   Please note that this is an initial development. There are many things to 
develop, but this is the starting point. Help is needed (and appreciated, for 
sure)!
   
   ## Impact
   
   Impact on user: Yes. Provide them `pip` to install Python packages.
   
   Impact on build: No.
   
   Impact on hardware: No.
   
   Impact on documentation: No.
   
   Impact on security: No.
   
   Impact on compatibility: No.
   
   ## Testing
   
   `rv-virt:python` can be used to test it:
   
   ### Building
   
   ```
   make -j distclean
   ./tools/configure.sh -S rv-virt:python
   kconfig-tweak -e FS_TMPFS && kconfig-tweak --set-val FS_HEAPSIZE 2097152
   kconfig-tweak --set-val RAM_SIZE 67108864
   kconfig-tweak -e INTERPRETERS_CPYTHON_ENABLE_PIP
   make olddefconfig
   make -j$(nproc)
   ```
   
   ### Running
   
   Please note that this Python distribution does not support the `_ssl` module 
yet, so `pip` can't download packages directly, but it still can be used to 
install packages locally. That being said, some preparation is required to 
download a python package on the host machine and, then, transferring it to 
QEMU.
   
   #### Preparing the Host to serve the Python package
   
   On the host machine, download the Python package and enable a local HTTP 
server:
   ```
   pip download --no-deps six -d /tmp/pip_serve/
   cd /tmp/pip_serve && python3 -m http.server 8080
   ``` 
   
   #### Running RISC-V QEMU
   
   ```
   qemu-system-riscv32 -semihosting -M virt,aclint=on -cpu rv32 -smp 8 -m 128 \
      -global virtio-mmio.force-legacy=false \
      -device virtio-serial-device,bus=virtio-mmio-bus.0 \
      -chardev 
socket,telnet=on,host=127.0.0.1,port=3450,server=on,wait=off,id=foo \
      -device virtconsole,chardev=foo \
      -device virtio-rng-device,bus=virtio-mmio-bus.1 \
      -netdev 
user,id=u1,hostfwd=tcp:127.0.0.1:10023-10.0.2.15:23,hostfwd=tcp:127.0.0.1:15001-10.0.2.15:5001
 \
      -device virtio-net-device,netdev=u1,bus=virtio-mmio-bus.2 \
      -drive file=./mydisk-1gb.img,if=none,format=raw,id=hd \
      -device virtio-blk-device,bus=virtio-mmio-bus.3,drive=hd \
      -bios none -kernel ./nuttx -nographic
   ABC[    0.040000] board_userled: LED 1 set to 0
   [    0.040000] board_userled: LED 2 set to 0
   [    0.040000] board_userled: LED 3 set to 0
   telnetd [5:100]
   
   NuttShell (NSH) NuttX-10.4.0
   nsh>
   ```
   
   Then, use `wget -o /tmp/six-1.17.0-py2.py3-none-any.whl 
http://<host_ip>:8080/six-1.17.0-py2.py3-none-any.whl` to download the package 
to the running QEMU. And, finally, install it with `pip`:
   
   ```
   nsh> wget -o /tmp/six-1.17.0-py2.py3-none-any.whl 
http://192.168.32.163:8080/six-1.17.0-py2.py3-none-any.whl
   nsh> python -m pip install --no-build-isolation --no-deps --no-index 
--target /tmp /tmp/six-1.17.0-py2.py3-none-any.whl
   [   46.190000] check_and_mount_romfs: Mounting ROMFS filesystem at 
target=/usr/local/lib with source=/dev/ram1
   WARNING: Disabling truststore since ssl support is missing
   Processing /tmp/six-1.17.0-py2.py3-none-any.whl
   Installing collected packages: six
   Successfully installed six-1.17.0
   WARNING: Running pip as the 'root' user can result in broken permissions and 
conflicting behaviour with the system package manager, possibly rendering your 
system unusable.It is recommended to use a virtual environment instead: 
https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you 
know what you are doing and want to suppress this warning.
   ```
   
   Installing the package may take a while (there is still room to optimize it. 
Help needed!)
   
   ### Results
   
   Check the package's version on Python:
   
   ```
   nsh> python
   [  288.150000] check_and_mount_romfs: Device is already mounted at 
/usr/local/lib
   Python 3.13.0 (main, May 14 2026, 12:56:07) [GCC 14.2.0] on nuttx
   Type "help", "copyright", "credits" or "license" for more information.
   >>> import six
   >>> six.__version__
   '1.17.0'
   >>> 
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to