Venv

Creating a new Python venv raspi_catch_object in the directory /usr/local/logistics/Python/venv:

1. Create venv raspi_catch_object

If not already existing, create the directory and set the access rights:

sudo mkdir /usr/local/logistics
cd /usr/local
sudo chown -R pi logistics && sudo chgrp -R pi logistics && sudo chmod -R a+rwx logistics
cd /usr/local/logistics
mkdir Python
cd Python
mkdir venv
cd venv

Create a new virtual environment in the venv directory and activate it:

cd /usr/local/logistics/Python/venv
python3 -m venv --system-site-packages raspi_catch_object
source raspi_catch_object/bin/activate
cd raspi_catch_object

It is very important to create the venv with the parameter –system-site-packages as to have access to pre-installed system-wide packages especially for using the camera. Otherwise Python packacke picamera2 will generate an error when importing it in a Python module.


2. Install system libraries

Install Required System Libraries

Run the following command to install the required dependencies for Pillow:

sudo apt install libjpeg-dev zlib1g-dev libfreetype6-dev liblcms2-dev libopenjp2-7-dev libtiff5-dev tk-dev libcap-dev  -y

Install FFmpeg and Development Libraries Run the following command to install the required FFmpeg libraries and development headers:

sudo apt install -y ffmpeg libavcodec-dev libavformat-dev libavdevice-dev libavutil-dev libavfilter-dev libswscale-dev libswresample-dev -y

Ensure that OpenBLAS is installed. This installs the necessary shared library (libopenblas.so.0) and development files:

sudo apt install -y libopenblas0 libopenblas-dev -y

Install the libcamera Package and its Python bindings:

sudo apt install -y libcamera-apps libcamera-dev python3-libcamera -y

Install the Python Kernel Mode Setting (KMS) bindings for working with DRM (Direct Rendering Manager) on Linux:

sudo apt install python3-kms++ -y

3. Install Python libraries

Install a precompiled binary wheel for av (if available), as a prereqisite for installing picamera2:

pip3 install av --only-binary :all:

Install picamera2:

pip3 install picamera2

Install a precompiled binary wheel for OpenCV (if available)

pip3 install opencv-python --only-binary :all:

Install RPi.GPIO library for controlling GPIO pins on the Raspberry Pi. :

sudo apt-get install python3-rpi.gpio

Copy the master requirements.txt to the virtual environment:

scp Friedrich@macbook-air.fritz.box:/Users/Friedrich/Documents/Logistics/venv/raspi_catch_object/requirements.txt /usr/local/logistics/Python/venv/raspi_catch_object

Install all Python libraries from the master requirements.txt in the virtual environment:

pip3 install -r requirements.txt