Using pyserial outside of docker container

I have some small test scripts which i want to use in torizon Verdin AM62 module which require the pyserial module.
I can’t seem to install the module as i constantly get the "
error: could not create ‘/usr/lib/python3.10/site-packages/serial’: Read-only file system
" error.
Is it possible to install this module outside the use of docker containers or not?

Any help is appreciated.

Kind regards,
Richard

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.

Greetings @RiBe_Act,

Typically if you want to install a new package on the host OS itself, you would need to use Yocto to customize the OS and add those new packages: Build Torizon OS from Source With Yocto Project/OpenEmbedded | Toradex Developer Center

Out of curiosity, what kind of test scripts are you trying to run outside of the container? And similarly, why do they need to be done outside of the container?

Best Regards,
Jeremias

Hi Jeremias,

They are nothing special, just some UART communication testing scripts.
It just that the whole Toradex, Embedded Linux in combination with Docker construction is very new to me and it seemed me simpler to just run the scripts from root o.s. since i just want to run them every now and then for debugging purposes.

On previous experiences with linux systems i was able to just install packages when needed and run the test scripts without a docker like system.

But as i understand it the design of the Torizon o.s. forces the use of docker containers for application development, now that i know this i’ll need to work with it i guess.

Kind regards,
Richard

If it helps, we do have a general article on accessing UART from within a container: How to Use UART on Torizon OS | Toradex Developer Center

Best Regards,
Jeremias