Skip to content

interpreters/python: Enable using pip to install Python packages#3487

Merged
linguini1 merged 1 commit into
apache:masterfrom
tmedicci:feature/python_pip
May 18, 2026
Merged

interpreters/python: Enable using pip to install Python packages#3487
linguini1 merged 1 commit into
apache:masterfrom
tmedicci:feature/python_pip

Conversation

@tmedicci
Copy link
Copy Markdown
Contributor

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 commit enables using `pip` as a pre-compiled (pyc) built-in
distributed along with cpython.

Signed-off-by: Tiago Medicci <tiago.medicci@espressif.com>
Copy link
Copy Markdown
Contributor

@linguini1 linguini1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

Copy link
Copy Markdown
Contributor

@cederom cederom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work @tmedicci thank you!! :-)

@acassis
Copy link
Copy Markdown
Contributor

acassis commented May 18, 2026

@tmedicci can we "pip install fastapi" and start using NuttX as web server for Cloud Application? :-D

@linguini1 linguini1 merged commit 8ba84ed into apache:master May 18, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants