Python Pyinstaller.exe文件未打开,其中包含人脸识别模块。(在.py中工作)
我已经用python编写了一个人脸识别代码。 我的代码在Python Pyinstaller.exe文件未打开,其中包含人脸识别模块。(在.py中工作),python,hook,pyinstaller,exe,face-recognition,Python,Hook,Pyinstaller,Exe,Face Recognition,我已经用python编写了一个人脸识别代码。 我的代码在.py文件中运行良好(没有任何错误或警告),但在从中生成.exe文件后,通过pyinstaller它将根本无法工作。 我已经搜索了一遍,寻找相同的方法,并尝试了以下方法,但仍然不起作用。 第一种方法我在.spec文件中做了以下更改。 (Windows操作系统) main.spec文件 有人说这可能是hook scipy.py文件的一个问题 hook-scipy.py 请帮我解决这个问题。通过这样做解决了上述问题 更改main.spec中的d
.py
文件中运行良好(没有任何错误或警告),但在从中生成.exe
文件后,通过pyinstaller
它将根本无法工作。
我已经搜索了一遍,寻找相同的方法,并尝试了以下方法,但仍然不起作用。
第一种方法我在.spec
文件中做了以下更改。
(Windows操作系统)
main.spec文件
有人说这可能是hook scipy.py文件的一个问题
hook-scipy.py
请帮我解决这个问题。通过这样做解决了上述问题 更改
main.spec
中的data=[]
对我来说很有效,现在我刚刚粘贴了所有这些文件[('shape\u predictor\u 68\u face\u landmarks.dat','./face\u recognition\u models/models'),('shape\u predictor\u face\u landmarks.dat','./face\u recognition\u models\u models/models'),('mmod\u human\u face\u faces\u detector\u detector.dat','人脸识别\u models/models'),('dlib_人脸识别_resnet_model_v1.dat','./人脸识别_models/models')]
在“main.py”所在的同一文件夹中,编辑main.spec
,然后运行命令pyinstaller main.spec
block_cipher = None
face_models = [
('.\\face_recognition_models\\models\\dlib_face_recognition_resnet_model_v1.dat', './face_recognition_models/models'),
('.\\face_recognition_models\\models\\mmod_human_face_detector.dat', './face_recognition_models/models'),
('.\\face_recognition_models\\models\\shape_predictor_5_face_landmarks.dat', './face_recognition_models/models'),
('.\\face_recognition_models\\models\\shape_predictor_68_face_landmarks.dat', './face_recognition_models/models'),
]
a = Analysis(['<your python script name.py>'],
pathex=['<path to working directory>'],
binaries=face_models,
datas=[],
hiddenimports=['scipy._lib.messagestream', 'scipy', 'scipy.signal', 'scipy.signal.bsplines', 'scipy.special', 'scipy.special._ufuncs_cxx',
'scipy.linalg.cython_blas',
'scipy.linalg.cython_lapack',
'scipy.integrate',
'scipy.integrate.quadrature',
'scipy.integrate.odepack',
'scipy.integrate._odepack',
'scipy.integrate.quadpack',
'scipy.integrate._quadpack',
'scipy.integrate._ode',
'scipy.integrate.vode',
'scipy.integrate._dop', 'scipy._lib', 'scipy._build_utils','scipy.__config__',
'scipy.integrate.lsoda', 'scipy.cluster', 'scipy.constants','scipy.fftpack','scipy.interpolate','scipy.io','scipy.linalg','scipy.misc','scipy.ndimage','scipy.odr','scipy.optimize','scipy.setup','scipy.sparse','scipy.spatial','scipy.special','scipy.stats','scipy.version'],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
a.datas += Tree('./scipy-extra-dll', prefix=None)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name='<your python script name>',
debug=False,
strip=False,
upx=True,
runtime_tmpdir=None,
console=True )
#replaced
datas=[]
#with
datas=[('shape_predictor_68_face_landmarks.dat','./face_recognition_models/models'),('shape_predictor_5_face_landmarks.dat','./face_recognition_models/models'),('mmod_human_face_detector.dat','./face_recognition_models/models'),('dlib_face_recognition_resnet_model_v1.dat','./face_recognition_models/models')]
import os
import glob
from PyInstaller.utils.hooks import get_module_file_attribute
from PyInstaller.compat import is_win
from PyInstaller.utils.hooks import collect_submodules
from PyInstaller.utils.hooks import collect_data_files
hiddenimports = collect_submodules('scipy')
datas = collect_data_files('scipy')
binaries = []
# package the DLL bundle that official scipy wheels for Windows ship
# The DLL bundle will either be in extra-dll on windows proper
# and in .libs if installed on a virtualenv created from MinGW (Git-Bash
# for example)
if is_win:
extra_dll_locations = ['extra-dll', '.libs']
for location in extra_dll_locations:
dll_glob = os.path.join(os.path.dirname(
get_module_file_attribute('scipy')), location, "*.dll")
if glob.glob(dll_glob):
binaries.append((dll_glob, "."))
# collect library-wide utility extension modules
hiddenimports = ['scipy._lib.%s' % m for m in [
'messagestream', "_ccallback_c", "_fpumode"]]