Skip to main content
 首页 » 编程设计

python之无法在 mac os X 上安装 dlib

2025年02月15日8虾米哥

我按照此处的说明进行操作:http://www.pyimagesearch.com/2017/03/27/how-to-install-dlib/

一行一行,除了安装python3的行。我创建了一个虚拟环境并在 virtualenv 中执行了以下四行:

$ pip install numpy 
$ pip install scipy 
$ pip install scikit-image 
$ pip install dlib 

与说明不同,最后一行只用了几秒钟,而不是 15 分钟。安装后,我打开ipython 并尝试import dlib,并收到此消息:

----> 1 from .dlib import * 
      2 __version__ = "19.4.0" 
 
ImportError: dlopen(/Users/myname/Documents/camera-project/code/story-board/cv/lib/python2.7/site-packages/dlib/dlib.so, 2): Library not loaded: @rpath/libmkl_rt.dylib 
  Referenced from: /Users/myname/Documents/camera-project/code/story-board/cv/lib/python2.7/site-packages/dlib/dlib.so 
  Reason: image not found 

我假设这意味着 dlib 没有正确安装,但我不确定我做错了什么?

此外,我应该补充一点,我的 mac 上没有anaconda,所以这不是问题所在。然而今天早些时候我做了,我可以毫无问题地加载 dlib,大概是因为我正在运行 anaconda 分发的 python 版本,我假设 dlib 带有 anaconda。但是 anaconda 分发的 X11 坏了所以我不得不从我的系统中完全删除 anaconda 并重新开始。

编辑

这是我在“成功”安装 dlib 后收到的消息:

    :/Library/Python/2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning. 
  SNIMissingWarning 
/Library/Python/2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning. 
  InsecurePlatformWarning 
Installing collected packages: dlib 
Successfully installed dlib-19.4.0 

请您参考如下方法:

您可能需要安装 pakage cmake。

刚才在我的 Mac 上尝试在 virtualenv 中安装 dlib 时出现错误

running bdist_wheel 
  running build 
  error: Cannot find cmake, ensure it is installed and in the path. 
  You can install cmake on OSX using `sudo brew install cmake`. 
  You can also specify its path with --cmake parameter. 

所以我建议尝试安装 cmake

brew install cmake