python - 依赖于 dlib 的 python 可执行文件不起作用
问题描述
大家好,我有一个依赖于 dlib 的 python 脚本,例如 import dlib 现在我已经创建了一个可执行文件(使用 pyinstaller),它在我的机器上运行良好,但出现 ImportError: DLL load failed: A dynamic link library (DLL ) 初始化例程在另一台机器上失败。在挖掘出发生这种情况的行之后,基本上是导入 dlib,这让我认为 dlib 没有正确包含在我的可执行文件中。我的 dlib 版本 19.18.0 和我试图运行 exe 的另一台机器没有安装 python。需要帮助 另一台机器上的错误
F:\FaceRecogDemo\FaceRecogDemo\dist>recognizefaces.exe --debug --encodings ../encodings.pickle --image ../example1.jpg
Traceback (most recent call last):
File "D:\FaceRecogDemo\recognizefaces.py", line 2, in <module>
File "c:\programdata\anaconda3\envs\mywindowscv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
File "D:\FaceRecogDemo\face_recognition\__init__.py", line 7, in <module>
File "c:\programdata\anaconda3\envs\mywindowscv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
File "D:\FaceRecogDemo\face_recognition\api.py", line 4, in <module>
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.
[14720] Failed to execute script recognizefaces
我的识别脸.py 脚本
import face_recognition
import argparse
import pickle
import cv2
# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-e", "--encodings", required=True,
help="path to serialized db of facial encodings")
ap.add_argument("-i", "--image", required=True,
help="path to input image")
ap.add_argument("-d", "--detection-method", type=str, default="cnn",
help="face detection model to use: either `hog` or `cnn`")
args = vars(ap.parse_args())
# load the known faces and embeddings
print("[INFO] loading encodings...")
data = pickle.loads(open(args["encodings"], "rb").read())
# load the input image and convert it from BGR to RGB
image = cv2.imread(args["image"])
rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# detect the (x, y)-coordinates of the bounding boxes corresponding
# to each face in the input image, then compute the facial embeddings
# for each face
print("[INFO] recognizing faces...")
boxes = face_recognition.face_locations(rgb,
model=args["detection_method"])
encodings = face_recognition.face_encodings(rgb, boxes)
# initialize the list of names for each face detected
names = []
# loop over the facial embeddings
for encoding in encodings:
# attempt to match each face in the input image to our known
# encodings
matches = face_recognition.compare_faces(data["encodings"],
encoding)
name = "Unknown"
# check to see if we have found a match
if True in matches:
# find the indexes of all matched faces then initialize a
# dictionary to count the total number of times each face
# was matched
matchedIdxs = [i for (i, b) in enumerate(matches) if b]
counts = {}
# loop over the matched indexes and maintain a count for
# each recognized face face
for i in matchedIdxs:
name = data["names"][i]
counts[name] = counts.get(name, 0) + 1
# determine the recognized face with the largest number of
# votes (note: in the event of an unlikely tie Python will
# select first entry in the dictionary)
name = max(counts, key=counts.get)
# update the list of names
names.append(name)
print(names)
我的两台机器都有 Windows 10 操作系统
解决方案
由于某种原因,Pyinstaller 似乎没有选择 dlib。在命令行上构建二进制文件时,请尝试使用以下标志将 dlib 显式添加到包中pyinstaller --hidden-import dlib
。
https://pyinstaller.readthedocs.io/en/stable/usage.html#what-to-bundle-where-to-search
推荐阅读
- java - 如何将 Json 转换为 java 中的集合?
- kotlin - Ktor 拦截器中的状态
- javascript - 我正在使用角度材料表可扩展行
- php - password_verify() 如何比较密码和散列密码?
- html - 如何在不影响其中的表单和按钮的情况下更改此 Bootstrap 4 卡的不透明度?
- java - 如何将数据从 Firebase 获取到哈希映射中?
- java - 从firebase检索数据后需要反转listview
- ansible - 使用 Ansible playbook 安装 Oracle12c
- jquery - 如何使用 jQuery/AJAX JSON 数据更新 HTML 列表
- javascript - 4点多项式的对角中心