mirror of
https://github.com/google-ai-edge/LiteRT.git
synced 2026-01-09 06:21:22 +08:00
Otherwise, I'll see ``` > [14/18] RUN pip3 install --require-hashes -r /tmp/requirements.txt: 0.735 error: externally-managed-environment 0.735 0.735 × This environment is externally managed 0.735 ╰─> To install Python packages system-wide, try apt install 0.735 python3-xyz, where xyz is the package you are trying to 0.735 install. 0.735 0.735 If you wish to install a non-Debian-packaged Python package, 0.735 create a virtual environment using python3 -m venv path/to/venv. 0.735 Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make 0.735 sure you have python3-full installed. 0.735 0.735 If you wish to install a non-Debian packaged Python application, 0.735 it may be easiest to use pipx install xyz, which will manage a 0.735 virtual environment for you. Make sure you have pipx installed. 0.735 0.735 See /usr/share/doc/python3.12/README.venv for more information. 0.735 0.735 note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages. 0.735 hint: See PEP 668 for the detailed specification. ------ hermetic_build.Dockerfile:101 -------------------- 99 | 100 | # Install Python dependencies securely using requirements file with hash verification 101 | >>> RUN pip3 install --require-hashes -r /tmp/requirements.txt 102 | 103 | # Set up environment variables for auto-configuration -------------------- ERROR: failed to solve: process "/bin/sh -c pip3 install --require-hashes -r /tmp/requirements.txt" did not complete successfully: exit code: 1 ``` LiteRT-PiperOrigin-RevId: 816541308
Building with Docker
This repository provides a Docker-based hermetic build environment that automatically configures all necessary dependencies for building the project without requiring manual configuration or setup. It handles both git submodule initialization and project configuration in a single step.
Prerequisites
- Docker installed on your machine
- Docker Compose (optional, for using docker-compose.yml)
Building with the Docker Script
- Clone this repository
- Run the build script:
./build_with_docker.sh
This will:
- Build a Docker image with all necessary dependencies
- Run the container, mounting the current litert checkout directory
- Generate the configuration file (.tf_configure.bazelrc)
- Build a target. We use
//litert/runtime:metricsas an example
Building with Docker Compose
Alternatively, you can use Docker Compose:
docker-compose up
Customizing the Build
To build different targets, you can either:
- Modify the
hermetic_build.Dockerfileand change the CMD line - Modify the command in
docker-compose.yml - Pass a custom command when running Docker:
docker run --rm --user $(id -u):$(id -g) -v $(pwd)/..:/litert_build litert_build_env bash -c "bazel build //litert/your_custom:target"
How It Works
The Docker environment:
- Sets up a Ubuntu 22.04 build environment (with newer libc/libc++)
- Installs Bazel 7.4.1 and necessary build tools
- Configures Android SDK and NDK with the correct versions
- Automatically initializes and updates git submodules
- Automatically generates the .tf_configure.bazelrc file
- Provides a hermetic build environment independent of your local setup
Troubleshooting
If you encounter build errors:
- Check that your Docker daemon has sufficient RAM and CPU allocated
- Ensure you have proper permissions to mount the current directory
- Check the Docker logs for any specific error messages
You can run a shell in the container for debugging:
docker run --rm -it --user $(id -u):$(id -g) -e HOME=/litert_build -e USER=$(id -un) -v $(pwd)/..:/litert_build litert_build_env bash