将库运行到python时出错 [英] Error to run a library to python

查看:99
本文介绍了将库运行到python时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照 http://npatta01.github.io/2015进行操作/08/10/dlib/,但是当我尝试运行(我使用sudo)时,

I follow the steps according to http://npatta01.github.io/2015/08/10/dlib/ but when I try to run (I use sudo),

python python_examples/face_detector.py examples/faces/2007_007763.jpg

取回错误. 首先,错误是

take back error. Firstly, the error was

AttributeError: 'module' object has no attribute 'image_window' 

到第8行. 现在,错误是Illegal instruction (core dumped),但我不知道为什么. 请帮助我正确添加库.

to line 8. Now, the error is Illegal instruction (core dumped) but I don't know why. Please, help me to add the library correctly.

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]))

推荐答案

我正在回答这个问题,因为我在做

I am answering this question because I ran into the same issue by doing

conda install -c conda-forge dlib

pip install dlib

我尝试搜索并获得了一些有用的链接,但下面的一个链接却被保存了下来.所以在这里也列出细节.

I tried searched and got several helpful links and below one link was saved my day. So listing down the details here too..

https://gist.github.com/ageitgey/629d75c1baac34dfa5ca2a1928a7aeaf

最好从Github编译最新代码,而不是从conda/pip安装.这是为了确保dlib在GUI支持下进行编译.

It will be better to compile the latest code from Github than installing it from conda / pip. This is to ensure that dlib is compiled with GUI support.

安装依赖项

sudo apt-get update

安装Boost

sudo apt-get install libboost-all-dev

安装其他依赖项(可能大多数已经安装在您的系统中)

Install other dependencies ( May be most of them will already have installed in your system)

apt-get install -y --fix-missing     build-essential     cmake     gfortran     git     wget     curl     graphicsmagick     libgraphicsmagick1-dev     libatlas-dev     libavcodec-dev     libavformat-dev     libboost-all-dev     libgtk2.0-dev     libjpeg-dev     liblapack-dev     libswscale-dev     pkg-config     python3-dev     python3-numpy     software-properties-common zip

apt-get clean

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

Build the latestst code of dlib from Github. Assumptions: - Ubuntu 16.04 or higher - don't have an nVidia GPU and don't have Cuda and cuDNN installed and don't want GPU acceleration

从github复制代码:

Clone the code from github:

git clone https://github.com/davisking/dlib.git

构建主要的dlib库:

Build the main dlib library:

cd dlib
    mkdir build; cd build; cmake .. -DDLIB_USE_CUDA=0 -DUSE_AVX_INSTRUCTIONS=1; cmake --build .

构建并安装Python扩展程序:

Build and install the Python extensions:

cd ..
    python setup.py install --yes USE_AVX_INSTRUCTIONS --no DLIB_USE_CUDA

确保指向正确的python(如果在Ubuntu的vanilla python顶部安装了anaconda,则应安装指向anaconda的软件包).

make sure are pointing to the right python( if you have anaconda installed on top of Ubuntu's vanilla python then you should install the package pointing anaconda).

如果您仍然遇到gcc错误,如下所示

if you are still facing a gcc error like below

lib/libstdc++.so.6: version `GLIBCXX_3.4.21' not found

然后确保您正在安装以下python软件包

then make sure you are installing the below python package

conda install libgcc

这时,您应该能够运行python并成功输入import dlib.

At this point, you should be able to run python and type import dlib successfully.

这篇关于将库运行到python时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆