Using pyserial outside of docker container

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


On TorizonCore, the root filesystem is read-only by design to ensure system stability and integrity. This is why you are encountering the “Read-only file system” error when trying to install the pyserial module directly on the system.

To use pyserial or any other Python module, the recommended approach is to use Docker containers. Containers provide a flexible and isolated environment where you can install and run your applications without modifying the underlying system.

Here’s a brief guide on how to set up a Docker container with pyserial on your Verdin AM62 module:

  1. Create a Dockerfile:
    Create a file named Dockerfile with the following content:

    FROM torizon/python:3.10-slim-bullseye
    
    RUN pip install pyserial
    
    COPY your_script.py /usr/src/app/
    
    CMD ["python", "/usr/src/app/your_script.py"]
    
  2. Build the Docker Image:
    On your development PC, navigate to the directory containing the Dockerfile and run:

    docker build -t my-python-app .
    
  3. Transfer the Docker Image to the Verdin Module:
    Save the Docker image to a tar file and transfer it to the Verdin module:

    docker save my-python-app -o my-python-app.tar
    scp my-python-app.tar torizon@<VERDIN_IP>:/home/torizon/
    
  4. Load the Docker Image on the Verdin Module:
    SSH into the Verdin module and load the Docker image:

    ssh torizon@<VERDIN_IP>
    docker load -i /home/torizon/my-python-app.tar
    
  5. Run the Docker Container:
    Run the container with the necessary device access:

    docker run --rm --device /dev/ttyUSB0 my-python-app
    

Replace /dev/ttyUSB0 with the appropriate UART device file for your setup.

By following these steps, you can use pyserial within a Docker container on TorizonCore without modifying the read-only root filesystem.

Please, also check if these links can help you solve your problem:

How to implement a Read-Only Rootfs (Linux) | Toradex Developer Center.