Installing
dlibon Raspberry Pi 5 with Python 3 using terminalIn this guide, we’ll walk through the steps to install the
dliblibrary on a Raspberry Pi 5 using Python 3 (compatible with Raspbian OS or ubunto versions from 18 to 23). This includes installing the necessary build tools, Python dependencies, compilingdlibfrom source, and setting up virtual environments for Python.Step 1: Install Required Build Tools for Ubuntu
Install the required build tools and libraries:
sudo apt-get install build-essential cmake pkg-config libx11-dev libatlas-base-dev libgtk-3-dev libboost-python-devStep 2: Install python3 dependencies
Install the Python 3 development tools and pip:
sudo apt-get install python3-dev python3-pipUpgrade pip and install numpy:
sudo -H pip3 install -U pip numpyStep 3: Compile
dlibfrom source.Download the
dlibsource code:wget http://dlib.net/files/dlib-19.9.tar.bz2Extract the tarball:
tar xvf dlib-19.9.tar.bz2Navigate to the extracted directory:
cd dlib-19.9/Create the build directory:
mkdir buildEnter the build directory:
cd buildConfigure the build using CMake:
cmake ..Build
dlib:cmake --build . --config ReleaseInstall
dlib:sudo make installUpdate the shared library cache:
sudo ldconfigcd ..Verify the installation:
pkg-config --libs --cflags dlib-1Step 4: Install virtual environment
Virtual environments in python is a great way to maintain different settings for each project. This way one can avoid package conflicts.
Install
virtualenvandvirtualenvwrapperfor Python 3:sudo pip3 install virtualenv virtualenvwrapperUpdate .bashrc to include virtual environment commands:
echo "# Python's Virtual Environment Wrapper" >> ~/.bashrcecho "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrcsource ~/.bashrcStep 5: installing the
dliblibraryCreate a virtual environment (e.g., named “Saber”):
mkvirtualenv Saber -p python3workon SaberInstall necessary Python libraries within this virtual environment:
pip install numpy scipy matplotlib scikit-image scikit-learn ipythonif you want to install
dlibfrom pippip install dlibAlternatively, if you compiled
dlibfrom source, move to the dlib root directory:cd dlib-19.9python setup.py install
quit virtual environmentdeactivateWhen attempting to install Python packages using
**Congratulations! your Python Dlib library is successfully installed.** {" "}pip, you might encounter this errorexternally-managed-environment. To resolve this, follow this link