Trouble installing Dlib for python on Mac OSX 10.1

2019-06-27 05:41发布

问题:

I'm trying to install dlib-18.16 for python on my computer (running Mac OSX 10.10). I have boost python installed as well as X11, but I've been running into trouble when running ./compile_dlib_python_module.bat as instructed to after downloading the files.

The errors I get are numerous, but look something like this

[  1%] Building CXX object dlib_build/CMakeFiles/dlib.dir/gui_widgets/fonts.o
In file included from /Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/fonts.cpp:14:
/Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:313:21: error: use
      of undeclared identifier 'XAllocColor'
                    XAllocColor(d, cmap, &xcol);

This continues for a while and ends with

/Users/xxx/Downloads/dlib-18.16/dlib/gui_widgets/nativefont.h:400:21: error: use
      of undeclared identifier 'XFillRectangle'
                    XFillRectangle(d, pix, gc, 0, 0, width, height);
                    ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[2]: *** [dlib_build/CMakeFiles/dlib.dir/gui_widgets/fonts.o] Error 1
make[1]: *** [dlib_build/CMakeFiles/dlib.dir/all] Error 2
make: *** [all] Error 2

I've checked for some of the missing functions like XFillRectangle, and found them declared in some .h files in the anaconda install of python (when looking at the dlib_build files, the installer seems to have located the anaconda install). Does anyone have any ideas as to how to fix this?

回答1:

I realized that I had to go into the CMakeCache.txt file and manually change the X11 path from anaconda to usr/X11, as the anaconda versions of the X11 .h files were missing some of these XQuartz functions. Everything works now.



回答2:

I had this issue with the version in PyPi (19.4.0). Installing directly from source (19.4.99) seems to work.

So something between those two versions has resolved this.

Commands to install from source:

git clone https://github.com/davisking/dlib.git
cd dlib
pip install .

FYI, here are the Xlib.h files I have on my system as the presumption is it was picking up a different version of XLib.h which didn't have these symbols.

Running on OS-X 10.11.4 with Python 2.7. I definitely have XQuartz installed.

$ mdfind -name Xlib.h
/usr/local/Cellar/dlib/19.4/share/doc/dlib/docs/dlib/gui_core/xlib.h.html
/usr/local/Cellar/dlib/19.4/include/dlib/gui_core/xlib.h
/Users/<username>/Workspace/dlib/dlib/gui_core/xlib.h
/System/Library/Frameworks/Tk.framework/Versions/8.4/Headers/X11/Xlib.h
/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11/Xlib.h
/opt/X11/include/X11/Xlib.h
/opt/X11/include/cairo/cairo-xlib.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Tk.framework/Versions/8.4/Headers/X11/Xlib.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11/Xlib.h