简体   繁体   中英

macOS - Trouble installing dlib

I wanted to work with Dlib for facial landmark detection and tried to install it on my macOS Sierra. I followed the instructions in the main GitHub Repo for dlib .

I first executed the following without errors after going into the examples folder:

mkdir build; cd build; cmake .. ; cmake --build .

Reverting back to the parent directory, I executed the following :

sudo python2.7 setup.py install

This encountered 20+ errors after completing 38%:

[ 35%] Building CXX object dlib_build/CMakeFiles/dlib.dir/timer/timer.cpp.o
[ 35%] Building CXX object dlib_build/CMakeFiles/dlib.dir/stack_trace.cpp.o
[ 36%] Building CXX object dlib_build/CMakeFiles/dlib.dir/gui_widgets/fonts.cpp.o
In file included from /Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/fonts.cpp:14:
/Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/nativefont.h:313:21: error: use of undeclared identifier 'XAllocColor'
                    XAllocColor(d, cmap, &xcol);
                    ^
/Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/nativefont.h:319:36: error: use of undeclared identifier 'XmbTextExtents'; did you mean 'XTextExtents'?
                            return XmbTextExtents(fs, str, len, ink, logical);
                                   ^~~~~~~~~~~~~~
                                   XTextExtents
/Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/nativefont.h:318:43: note: 'XTextExtents' declared here
                        inline static int XTextExtents (XFontSet fs, char *str, int len, XRectangle *ink, XRectangle *logical){
                                          ^
/Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/nativefont.h:322:36: error: use of undeclared identifier 'XwcTextExtents'; did you mean 'XTextExtents'?
                            return XwcTextExtents(fs, str, len, ink, logical);
                                   ^~~~~~~~~~~~~~
                                   XTextExtents
/Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/nativefont.h:321:43: note: 'XTextExtents' declared here
                        inline static int XTextExtents (XFontSet fs, wchar_t *str, int len, XRectangle *ink, XRectangle *logical){
                                          ^
/Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/nativefont.h:325:29: error: use of undeclared identifier 'XmbDrawString'; did you mean 'XDrawString'?
                            XmbDrawString(d, w, fs, gc, x, y, str, num_bytes);
                            ^~~~~~~~~~~~~
                            XDrawString
/Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/nativefont.h:324:44: note: 'XDrawString' declared here
                        inline static void XDrawString(Display *d, Window w, XFontSet fs, GC gc, int x, int y, char *str, int num_bytes){
                                           ^
/Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/nativefont.h:328:29: error: use of undeclared identifier 'XwcDrawString'; did you mean 'XDrawString'?
                            XwcDrawString(d, w, fs, gc, x, y, str, num_bytes);
                            ^~~~~~~~~~~~~
                            XDrawString
/Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/nativefont.h:327:44: note: 'XDrawString' declared here
                        inline static void XDrawString(Display *d, Window w, XFontSet fs, GC gc, int x, int y, wchar_t *str, int num_bytes){
                                           ^
/Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/nativefont.h:334:29: error: use of undeclared identifier 'XOpenDisplay'
                        d = XOpenDisplay(NULL);
                            ^
/Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/nativefont.h:337:33: error: use of undeclared identifier 'XOpenDisplay'
                            d = XOpenDisplay(":0.0");
                                ^
/Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/nativefont.h:369:29: error: use of undeclared identifier 'XFreeFontSet'
                            XFreeFontSet(d, fs);
                            ^
/Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/nativefont.h:371:30: error: use of undeclared identifier 'XCreateFontSet'
                        fs = XCreateFontSet(d, fontset, &mlist, &mcount, &def_str);
                             ^
/Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/nativefont.h:376:34: error: use of undeclared identifier 'XExtentsOfFontSet'
                        extent = XExtentsOfFontSet(fs);
                                 ^
/Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/nativefont.h:379:25: error: use of undeclared identifier 'XFreeStringList'; did you mean 'XwcFreeStringList'?
                        XFreeStringList(mlist);
                        ^~~~~~~~~~~~~~~
                        XwcFreeStringList
/Users/Ajay/anaconda/include/X11/Xutil.h:777:13: note: 'XwcFreeStringList' declared here
extern void XwcFreeStringList(
            ^
In file included from /Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/fonts.cpp:14:
/Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/nativefont.h:379:41: error: cannot initialize a parameter of type 'wchar_t **' with an lvalue of type 'char **'
                        XFreeStringList(mlist);
                                        ^~~~~
/Users/Ajay/anaconda/include/X11/Xutil.h:781:1: note: passing argument to parameter here
);
^
In file included from /Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/fonts.cpp:14:
/Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/nativefont.h:388:29: error: use of undeclared identifier 'XFreeGC'
                            XFreeGC(d, gc);
                            ^
/Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/nativefont.h:389:29: error: use of undeclared identifier 'XFreePixmap'
                            XFreePixmap(d, pix);
                            ^
/Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/nativefont.h:393:103: error: use of undeclared identifier 'XDefaultDepth'
                        pix = XCreatePixmap(d, DefaultRootWindow(d), pix_width_prev, pix_height_prev, XDefaultDepth(d, DefaultScreen(d)));
                                                                                                      ^
/Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/nativefont.h:394:30: error: use of undeclared identifier 'XCreateGC'
                        gc = XCreateGC(d, pix, 0, NULL);
                             ^
/Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/nativefont.h:398:21: error: use of undeclared identifier 'XSetForeground'
                    XSetForeground(d, gc, backcolor);
                    ^
/Users/Ajay/Framework_libraries/dlib/dlib/gui_widgets/nativefont.h:399:21: error: use of undeclared identifier 'XSetBackground'
                    XSetBackground(d, gc, backcolor);
                    ^
/Users/Ajay/Framework_libraries/dlib/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.cpp.o] Error 1
make[1]: *** [dlib_build/CMakeFiles/dlib.dir/all] Error 2
make: *** [all] Error 2
error: cmake build failed!

Looking into it a bit, I have the feeling that there is a small path (to python) that I need to change to get everything to work. Referring a similar problem , he changed some path in the CMakeCache.txt, but I'm not exactly sure which line/part. Furthermore, there are 4 CMakeCache.txt files. Which one (if any) should I change?

Ajays-MacBook-Pro:dlib Ajay$ find . -name "CMakeCache.txt"
./examples/build/CMakeCache.txt
./examples/build/cpp11_test_build/CMakeCache.txt
./tools/python/build/CMakeCache.txt
./tools/python/build/cpp11_test_build/CMakeCache.txt

Is there any other solution to this? What should I do? Any help would be appreciated!

See my answer here

Long story short, you can get this issue even with xQuartz installed .

The latest version in Git seems to work, but the PyPi repository has not been updated.

Until then, use these commands:

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

I could not use Dlib because of the multiple python versions installed on my computer. Macbook Pro (2014) comes preinstalled with python2.7.10 that should not be updated. If newer versions are required, they need to be installed alongside v2.7. I used anaconda and installed python3.5 on my computer. However, this seemed to be source of problems stated in the question. Once Anaconda and python3.5 was uninstalled, Dlib started working with no errors. The reason is unclear, but still a satisfactory work around.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM