'How to install dlib on mac?

I have error as below and cannot install dlib. Pls help me, how to install dlib on mac.

/Users/mac/PycharmProjects/pythonProject/venv/bin/python /Users/mac/PycharmProjects/pythonProject/main.py
Traceback (most recent call last):
  File "/Users/mac/PycharmProjects/pythonProject/main.py", line 1, in <module>
    import face_recognition
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/face_recognition-1.3.0-py3.10.egg/face_recognition/__init__.py", line 7, in <module>
    from .api import load_image_file, face_locations, batch_face_locations, face_landmarks, face_encodings, compare_faces, face_distance
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/face_recognition-1.3.0-py3.10.egg/face_recognition/api.py", line 4, in <module>
    import dlib
ModuleNotFoundError: No module named 'dlib'


Solution 1:[1]

Note that "import" doesn't install any libraries/packages, it only brings packages that you've already installed to your program.

From the path in the error message, it seems you're using PyCharm. PyCharm projects use virtual environments (which I do recommend for projects). In each environment, the Python interpreter, packages, and scripts are isolated from your main install or these in other virtual environments. This is probably why dlib isn't in your environment yet.

There are two potential solutions.

  1. When you're creating the project, you can check "Inherit global-site packages", and the environment will inherit packages, including dlib if you've already installed it.
  2. Go to Packages Manager. There you can install new packages to the project's environment, including dlib.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Arthur