-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Description
Hi,
You might want to freeze your script into a standalone executable to run on any system without the need of installing python or face_recognition and maybe you want to create a demo for your application and want to give it to someone else without giving your source code. Here is a simple tutorial to do that. I tested this method with python3.6 on Windows 10, but I think you can get it working on Linux with a similar method.
- Make sure you have correctly installed both
face_recognitionanddliband you see no error when importing them into your script. - Make sure your script works fine, and all its dependencies are right next to it, and you can run it fine with
python yourscript.py. - Install Pyinstaller with
pip:
pip install pyinstaller - Create a new directory and move your python script and all dependencies into it. I call it
myprojectandmyscript.py - Copy
face_recognition_modelsandscipy-extra-dllfrom your python installed directory to your project directory. - Create an empty file called
<yourscriptname>.speclikemyscript.specnext to your python script. - Use below Pyinstaller spec file sample and edit some parts according to your needs: (I mark it with
<>tag)
# -*- mode: python -*-
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 )
- Generate your executable with
python -m pyinstaller myscript.spec - If you see no error then your executable can be found in
distdirectory. - Enjoy!
Thanks to @ageitgey and @davisking for their awesome work.
PascPeli, hbeyan, alexpardede, MrYZD, rezayoga and 15 morefordffx, sandip-narwade, Legorooj, saadi-tech and ismam3sandip-narwade, Legorooj, taufardh and ismam3davisking, hanyh0807, mariocesarc, mostafazaghlol, amanbadal890 and 7 moresandip-narwade, Legorooj, taufardh, saadi-tech, ismam3 and 1 moresandip-narwade, Legorooj and saadi-tech
Metadata
Metadata
Assignees
Labels
No labels