Unable to install llama cpp python library in App Lab

Hello,

I have been trying to install Llama CPP Python library on Arduino Uno Q for running smaller llms. I tried installing via Requirements.txt in arduino app lab but it gave the following error.

Using CPython 3.13.9 interpreter at: /usr/local/bin/python
Creating virtual environment at: .cache/.venv
Activating python virtual environment
Using Python 3.13.9 environment at: .cache/.venv
Resolved 6 packages in 11.95s
Building llama-cpp-python==0.3.20
Downloading numpy (14.9MiB)
Downloading numpy
× Failed to build llama-cpp-python==0.3.20
├─:play_button: The build backend returned an error
╰─:play_button: Call to scikit_build_core.build.build_wheel failed (exit status: 1)
[stdout]
*** scikit-build-core 0.12.2 using CMake 4.3.1 (wheel)
*** Configuring CMake...
loading initial cache file /tmp/tmpy6_yu2lo/build/CMakeInit.txt
-- Configuring incomplete, errors occurred!
[stderr]
CMake Error at
/app/.cache/uv/builds-v0/.tmp1BZIbL/lib/python3.13/site-packages/cmake/data/share/cmake-4.3/Modules/CMakeDetermineCCompiler.cmake:48
(message):
Could not find the compiler specified in the environment variable CC:
gcc.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
*** CMake configuration failed
hint: This usually indicates a problem with the package or the build
environment.
Clearing cache at: .cache/uv
Removed 8015 files (283.9MiB)

Please help me solve this error and how i can fix this. Also, is there any other ways i can run llms (mostly under 1B parameters ) in arduino uno q (4gb ram varient)?.

Thanks.

Ciao @n1lzer0

take a look ath this project on project hub :)

Thanks for the help.

But i wanted to use llama cpp as a python package inside app lab and in this project, it has been used outside the app lab ie in the board's terminal.

Update:
I further checked into the error and it apparently requires some c++ tools to build the package which was included in build-essential package.

So i ran this command in boards' shell

sudo apt install build-essential 

Unfortunately upon installing the said package. it still gave the same error.

The Python script of the App runs in a Docker container. This is an isolated environment. So changes you make in the primary operating system's environment have no effect on the environment in which the Python script is executed, and vice versa.

Is there any way i can install this in the docker container?

ooo idk bout this topic... TIME TO LEARN

Will you tell me what's ur issue?

The issue is, i was trying to install llama cpp python library, which requries some c++ based packages. However, these packages are required to be installed in the docker container, which is not possible for now i think. I would try to build the package as a server outside the docker enviroment as suggested by @AndreaRichetta and then access it from applab by connecting to it.

Will further update this if it works.

The following is a one line command to download and install ollama. The default installation script fails because the tar archive includes large files for NVIDIA CUDA cores. Since Uno Q does not have CUDA cores, the CUDA libraries are excluded. The tar archive contains compiled ARM64 code so no compiling hassles.

curl -fsSL https://ollama.com/download/ollama-linux-arm64.tar.zst | sudo tar x --zstd --exclude="lib/ollama/cuda_v1[23]" -C /usr/local/

After this finishes, the following new files should exist.

/usr/local/bin/ollama   # executable
/usr/local/lib/ollama/  # libraries
/usr/local/lib/ollama/libggml-base.so -> libggml-base.so.0
/usr/local/lib/ollama/libggml-base.so.0 -> libggml-base.so.0.0.0
/usr/local/lib/ollama/libggml-base.so.0.0.0
/usr/local/lib/ollama/libggml-cpu.so

Use ollama like this to run the smollm:360m model. The model is stored in the hidden directory ~/.ollama so it is much faster to start after the first use. ollama has an HTTP REST API so it should be accessible from an app lab app. The python lib is named ollama.

ollama serve
ollama run smollm:360m

Thanks for the help.

I installed ollama this way and it worked. Tried running LFM2.5-1.2B-instruct and it worked great :D . However, to access it through python code, It needs to be "exposed" i.e we should be able to access it by the port (the default port is 11434). For this,
we need to edit the service file via

systemctl edit ollama.service

Unfortunately, It showed the following error.

arduino@Baymax:~$ sudo systemctl edit ollama.service
No files found for ollama.service.
Run 'systemctl edit --force --full ollama.service' to create a new unit.

I dont know how to create and edit a service file and what i have to add, for it to run. (I tried it once in windows for another program but i dont know how to do so in linux).

I found the ollama install.sh creates all the systemd stuff so "ollama serve" runs as a service. This is essential so version 2 of the one line command follows. This runs the ollama Linux installation script which is modified on the fly to exclude the CUDA files.

curl -fsSL https://ollama.com/install.sh | sed 's/\(tar.*xf - \)/\1--exclude=\"lib\/ollama\/cuda_v1[23]\" /' | sh

The ollama service now runs as user ollama so models are stored in /usr/share/ollama/.ollama. This is in the rather small root partition so be careful not to fill up the root partition.

This is the state of my root partition with the smollm:360m model installed.

arduino@UnoKyu:/usr/share$ df -h /
Filesystem       Size  Used Avail Use% Mounted on
/dev/mmcblk0p68  9.8G  8.0G  1.3G  87% /

Perhaps symbolic links can redirect model storage to the /home/arduino partition, if needed. I removed the .ollama/models directory in /home/arduino since it is no longer used.

With the addition of custom bricks (the docker one) , is it possible now to somehow add the required packages using it?

Hi @n1lzer0. You are definitely on the right track!

The custom Bricks feature does not allow you to customize the contents of the primary Docker container in which the App's Python script runs. However, it does allow you to run additional custom containers, which the Python script can interface with. This is actually how some of the official Bricks provided by Arduino work already.

Unfortunately we haven't published documentation for the custom Bricks feature yet, but the documentation team have already produced a draft of the documentation, which you can access here in the documentation source repository:

https://github.com/arduino/docs-content/blob/app-lab-custom-bricks-documentation/content/software/app-lab/5.bricks/3.custom-bricks/custom-bricks.md

Note that the brick_compose.yaml file in the custom Brick is a Docker compose file, so the documentation provided by Docker will also be applicable:

You might be able to find an existing Docker image published on an image registry (e.g., Docker Hub that provides all the capabilities you require. Alternatively, you can create your own custom image. If you create a custom image, you should note that (at least currently), you must manage this manually. Since Arduino App Lab takes care of managing the App's containers for the user, you might expect that it would handle building the container from the image source automagically, but unfortunately this is not supported. The "gotcha" is that it will actually build the container the first time you start an App with a custom Brick that references a local image source. However, afterwards you will run into a confusing situation where changes you make to the image source don't have any effect on the behavior of the Brick, due to the fact that Arduino App Lab / Arduino App CLI doesn't rebuild the container as needed (arduino/arduino-app-cli#389) and will instead simply continue to use the container it built from the previous version of the image source on the first run.

I'm happy to provide some assistance with managing containers built from a custom image source if you end up going that route.

Here are some examples of custom Bricks that use a dedicated container:

You may find some relevant information in the discussion on this forum topic:

I have noticed a LLM Brick in About Bricks in AppLab documentation(Perhaps to be used in Ventuno Q).

Can it be used in Uno Q to run lower LLMs?

@n1lzer0 ollama works on uno q with a little extra work. Much easier than llama.cpp to get working. Or are you only interested in llama.cpp? Also I am talking about running ollama server outside of app lab/docker. It is possible to run ollama server outside docker then inside docker main.py can use the python ollama client library to access the ollama server via HTTP API.

If you have ollama correctly installed on Uno Q outside docker/app lab/brick, it defaults to only accepting connection from localhost. If you want to access ollama server on Uno Q from another computer you can change the default like this

sudo systemctl edit ollama.service

Then add the following.

[Service]
Environment="OLLAMA_HOST=0.0.0.0"

Save the change then do the following to activate the change.

sudo systemctl daemon-reload
sudo systemctl restart ollama

You can get the same or better answer by asking gemini or chatgpt.

how to expose ollama server to the non localhost computers on Linux?

I have an update on this subject. The documentation has now been completed and published:

https://docs.arduino.cc/software/app-lab/bricks/custom-bricks/