fbpx [フレーム]

Install Dlib on MacOS

In this post, we will provide step by step instructions on how to install Dlib on MacOS and OSX. The installation instructions are slightly different for different versions of the operating system and XCode. Please choose the right one for you. Install Dlib on MacOS >= 10.11 & XCode >=


In this post, we will provide step by step instructions on how to install Dlib on MacOS and OSX. The installation instructions are slightly different for different versions of the operating system and XCode. Please choose the right one for you.

Install Dlib on MacOS >= 10.11 & XCode >= 8

Step 1: Install OS libraries

brew cask install xquartz
brew install gtk+3 boost
brew install boost-python --with-python3

Step 2: Install Python 2 and/or Python 3

brew install python python3
brew link python
brew link python3
# check whether Python using homebrew install correctly
which python2 # it should output /usr/local/bin/python2
which python3 # it should output /usr/local/bin/python3
# check Python versions
python2 --version
python3 --version

Python version (2.6 or 2.7, 3.5 or 3.6) installed on your machine is required to determine path of Python’s site-packages. It will be used later.

Step 3: Install Python libraries

We are going to use a Virtual Environment to install Python libraries. It is generally a good practice to separate your project environment and global environment.

# Install virtual environment
pip install virtualenv virtualenvwrapper
echo "# Virtual Environment Wrapper"
echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bash_profile
source ~/.bash_profile
############ For Python 2 ############
# create virtual environment
mkvirtualenv facecourse-py2 -p python2
workon facecourse-py2
# now install python libraries within this virtual environment
pip install numpy scipy matplotlib scikit-image scikit-learn ipython
# quit virtual environment
deactivate
############ For Python 3 ############
# create virtual environment
mkvirtualenv facecourse-py3 -p python3
workon facecourse-py3
# now install python libraries within this virtual environment
pip install numpy scipy matplotlib scikit-image scikit-learn ipython
# quit virtual environment
deactivate

Step 4: Install Dlib

Step 4.1: Compile C++ library

brew install dlib

Step 4.2: Compile Python module

Now activate "facecourse-py2" or "facecourse-py3" virtual environment based on whether you were following the process for Python2 or Python3.

############ For Python 2 ############
workon facecourse-py2
############ For Python 3 ############
workon facecourse-py3

We will now install Dlib using pip.

pip install dlib

Installation is complete. You can now exit from virtualenv using deactive.

deactivate

Install Dlib on MacOS 10.10 & XCode < 8

Step 1: Install OS libraries

brew cask install xquartz
brew install gtk+3 boost
brew install boost-python --with-python3

Step 2: Install Python 2 and/or Python 3

brew install python python3
brew link python
brew link python3
# check whether Python using homebrew install correctly
which python2 # it should output /usr/local/bin/python2
which python3 # it should output /usr/local/bin/python3
# check Python versions
python2 --version
python3 --version

Python version (2.6 or 2.7, 3.5 or 3.6) installed on your machine is required to determine path of Python’s site-packages. It will be used later.

Step 3: Install Python libraries

We are going to use a Virtual Environment to install Python libraries. It is generally a good practice to separate your project environment and global environment.

# Install virtual environment
pip install virtualenv virtualenvwrapper
echo "# Virtual Environment Wrapper"
echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bash_profile
source ~/.bash_profile
############ For Python 2 ############
# create virtual environment
mkvirtualenv facecourse-py2 -p python2
workon facecourse-py2
# now install python libraries within this virtual environment
pip install numpy scipy matplotlib scikit-image scikit-learn ipython
# quit virtual environment
deactivate
############ For Python 3 ############
# create virtual environment
mkvirtualenv facecourse-py3 -p python3
workon facecourse-py3
# now install python libraries within this virtual environment
pip install numpy scipy matplotlib scikit-image scikit-learn ipython
# quit virtual environment
deactivate

Step 4: Compile DLib

Step 4.1: Compile C++ binary

Dlib uses few C++11 features which XCode 7 does not support. We have patched Dlib v19.4 by replacing this feature with Dlib’s internal function. This patched version of Dlib compiles with XCode 7. So if you are using XCode 7, use branch v19.4-thread-local-patch of our Dlib fork in your projects.

Davis King, creator of Dlib, recommends using CMake for using Dlib in your code. But if you want to use Dlib as a library follow these steps:

git clone https://github.com/vaibhawchandel/dlib.git
cd dlib
git checkout v19.4-thread-local-patch
mkdir build
cd build
cmake ..
cmake --build . --config Release
make install
cd ..

Now you can use pkg-config to provide path to Dlib’s include directory and link Dlib library file.

pkg-config --libs --cflags dlib-1

Step 4.2: Compile Python module

Now activate "facecourse-py2" or "facecourse-py3" virtual environment based on whether you were following the process for Python2 or Python3.

############ For Python 2 ############
workon facecourse-py2
############ For Python 3 ############
workon facecourse-py3

Now run the following command to build Python module.

python setup.py install

For consistency we have installed Python and C++ binaries of Dlib using same source code.

Since we installed dlib in facecource-py3/facecourse-py2 virtualenv, dlib was installed only in this virtualenv and not globally. So whenever you want to use dlib, you have to activate the virtualenv using workon command as we used earlier in this post.

Now exit from virtualenv

deactivate
Was This Article Helpful?

Table of Contents

Was This Article Helpful?

Read Next

Shubham October 7, 2025

VideoRAG: Redefining Long-Context Video Comprehension

Discover VideoRAG, a framework that fuses graph-based reasoning and multi-modal retrieval to enhance LLMs' ability to understand multi-hour videos efficiently.

Kukil September 30, 2025

AI Agent in Action: Automating Desktop Tasks with VLMs

Learn how to build AI agent from scratch using Moondream3 and Gemini. It is a generic task based agent free from…

Bhomik Sharma September 23, 2025

The Ultimate Guide To VLM Evaluation Metrics, Datasets, And Benchmarks

Get a comprehensive overview of VLM Evaluation Metrics, Benchmarks and various datasets for tasks like VQA, OCR and Image Captioning.

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.

Subscribe to receive the download link, receive updates, and be notified of bug fixes

Which email should I send you the download link?

  • We hate SPAM and promise to keep your email address safe.

Get Started with OpenCV

  • FREE OpenCV Crash Course
  • Getting Started Guides
  • Installation Packages
  • C++ And Python Examples
  • Newsletter Insights
  • We hate SPAM and promise to keep your email address safe.
Subscribe To Receive
  • FREE OpenCV Crash Course
  • Getting Started Guides
  • Installation Packages
  • C++ And Python Examples
  • Newsletter Insights

We hate SPAM and promise to keep your email address safe.​

  • We hate SPAM and promise to keep your email address safe.

AltStyle によって変換されたページ (->オリジナル) /