运行python库时出错

运行python库时出错,python,attributeerror,dlib,illegal-instruction,Python,Attributeerror,Dlib,Illegal Instruction,我按照以下步骤进行操作,但当我尝试跑步时(我使用sudo) 收回错误。 首先,错误是 AttributeError: 'module' object has no attribute 'image_window' 到第8行。 现在,错误是非法指令(内核转储),但我不知道为什么。 请帮助我正确添加库 import sys import dlib from skimage import io detector = dlib.get_frontal_face_detector() win =

我按照以下步骤进行操作,但当我尝试跑步时(我使用sudo)

收回错误。 首先,错误是

AttributeError: 'module' object has no attribute 'image_window' 
到第8行。 现在,错误是
非法指令(内核转储)
,但我不知道为什么。 请帮助我正确添加库

import sys

import dlib
from skimage import io


detector = dlib.get_frontal_face_detector()
win = dlib.image_window()

for f in sys.argv[1:]:
    print("Processing file: {}".format(f))
    img = io.imread(f)
    # The 1 in the second argument indicates that we should upsample the image
    # 1 time.  This will make everything bigger and allow us to detect more
    # faces.
    dets = detector(img, 1)
    print("Number of faces detected: {}".format(len(dets)))
    for i, d in enumerate(dets):
        print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format(
            i, d.left(), d.top(), d.right(), d.bottom()))

    win.clear_overlay()
    win.set_image(img)
    win.add_overlay(dets)
    dlib.hit_enter_to_continue()


# Finally, if you really want to you can ask the detector to tell you the score
# for each detection.  The score is bigger for more confident detections.
# The third argument to run is an optional adjustment to the detection threshold,
# where a negative value will return more detections and a positive value fewer.
# Also, the idx tells you which of the face sub-detectors matched.  This can be
# used to broadly identify faces in different orientations.
if (len(sys.argv[1:]) > 0):
    img = io.imread(sys.argv[1])
    dets, scores, idx = detector.run(img, 1, -1)
    for i, d in enumerate(dets):
        print("Detection {}, score: {}, face_type:{}".format(
            d, scores[i], idx[i]))
正如我在你的代码中看到的:

detector = dlib.get_frontal_face_detector()
win = dlib.image_window()
第一行工作,第二行不行。这意味着安装了dlib,但编译时不支持GUI

我们看到,如果定义了宏DLIB_NO_GUI_支持,那么DLIB模块中就不会有“image_window”函数。如果CMake脚本找不到X11库,则会自动定义此宏

您需要确保使用GUI支持编译dlib。要做到这一点,首先,如果您使用的是Linux或XQuartz for Mac,请将libx11 dev安装到您的系统中

当通过运行
python setup.py install构建dlib时——是dlib\u JPEG\u支持
——检查其消息。如果有错误或警告,请按照我在代码中看到的那样修复它们:

detector = dlib.get_frontal_face_detector()
win = dlib.image_window()
第一行工作,第二行不行。这意味着安装了dlib,但编译时不支持GUI

我们看到,如果定义了宏DLIB_NO_GUI_支持,那么DLIB模块中就不会有“image_window”函数。如果CMake脚本找不到X11库,则会自动定义此宏

您需要确保使用GUI支持编译dlib。要做到这一点,首先,如果您使用的是Linux或XQuartz for Mac,请将libx11 dev安装到您的系统中


当通过运行
python setup.py install构建dlib时——是dlib\u JPEG\u支持
——检查其消息。如果有错误或警告-修复它们

我回答这个问题是因为我在执行以下操作时遇到了相同的问题

conda install -c conda-forge dlib

我试着搜索,得到了几个有用的链接,下面的一个链接保存了我的一天。所以在这里也列出了细节

从Github编译最新代码比从conda/pip安装代码要好。这是为了确保使用GUI支持编译dlib

安装依赖项

sudo-apt-get-update

安装增压器

sudo apt-get install libboost-all-dev
安装其他依赖项(可能大多数依赖项已经安装在您的系统中)

从Github构建dlib的最新代码。 假设: -Ubuntu 16.04或更高版本 -没有nVidia GPU,没有安装Cuda和cuDNN,不希望GPU加速

从github克隆代码:

git clone https://github.com/davisking/dlib.git
构建主dlib库:

cd dlib
    mkdir build; cd build; cmake .. -DDLIB_USE_CUDA=0 -DUSE_AVX_INSTRUCTIONS=1; cmake --build .
构建并安装Python扩展:

cd ..
    python setup.py install --yes USE_AVX_INSTRUCTIONS --no DLIB_USE_CUDA
确保你指向正确的python(如果你在Ubuntu的香草python上安装了anaconda,那么你应该安装指向anaconda的包)

如果您仍然面临下面这样的gcc错误

lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not found
然后确保您正在安装下面的python包

conda install libgcc

此时,您应该能够成功地运行python并键入import dlib。

我回答这个问题是因为我在

conda install -c conda-forge dlib

我试着搜索,得到了几个有用的链接,下面的一个链接保存了我的一天。所以在这里也列出了细节

从Github编译最新代码比从conda/pip安装代码要好。这是为了确保使用GUI支持编译dlib

安装依赖项

sudo-apt-get-update

安装增压器

sudo apt-get install libboost-all-dev
安装其他依赖项(可能大多数依赖项已经安装在您的系统中)

从Github构建dlib的最新代码。 假设: -Ubuntu 16.04或更高版本 -没有nVidia GPU,没有安装Cuda和cuDNN,不希望GPU加速

从github克隆代码:

git clone https://github.com/davisking/dlib.git
构建主dlib库:

cd dlib
    mkdir build; cd build; cmake .. -DDLIB_USE_CUDA=0 -DUSE_AVX_INSTRUCTIONS=1; cmake --build .
构建并安装Python扩展:

cd ..
    python setup.py install --yes USE_AVX_INSTRUCTIONS --no DLIB_USE_CUDA
确保你指向正确的python(如果你在Ubuntu的香草python上安装了anaconda,那么你应该安装指向anaconda的包)

如果您仍然面临下面这样的gcc错误

lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not found
然后确保您正在安装下面的python包

conda install libgcc

此时,您应该能够成功运行python并键入import dlib。

您能发布代码吗?发生的情况是,您试图访问另一个模块中名为image\u window的函数或对象,但它不存在。欢迎使用StackOverflow。请阅读并遵循帮助文档中的发布指南。适用于这里。在您发布代码并准确描述问题之前,我们无法有效地帮助您。由于您没有充分描述开始时所做的操作、更改的内容,也没有提供完整的错误消息,我们真的无法提供帮助。@PatrickHaugh是的,关于“win=dlib.image_window()”的错误,但为什么?到其他pc它运行。@Prune我不知道我更改了什么。在第一个错误之后,我尝试使用eclipse将库运行到C/C++中,但我也失败了,我再次尝试将库运行到python中,我遇到了第二个错误。你能发布你的代码吗?发生的情况是,您试图访问另一个模块中名为image\u window的函数或对象,但它不存在。欢迎使用StackOverflow。请阅读并遵循帮助文档中的发布指南。适用于这里。在您发布代码并准确描述问题之前,我们无法有效地帮助您。由于您没有充分描述开始时所做的操作、更改的内容,也没有提供完整的错误消息,我们真的无法提供帮助。@PatrickHaugh是的,关于“win=dlib.image_window()”的错误,但为什么?到其他pc它运行。@Prune我不知道我更改了什么。在第一个错误之后,我尝试使用eclipse将库运行到C/C++中,但我也失败了,我再次尝试将库运行到python中,我遇到了第二个错误。你是对的。来自
python setup.py安装--yes DLIB\u JPEG\u SUPPORT
的消息是
CMake Error at