From 2cb712374a6916df4ecf6464753da7b3da3e4fea Mon Sep 17 00:00:00 2001 From: Andreas Stange Date: Mon, 16 Aug 2021 17:31:44 +0200 Subject: [PATCH] create executable using pyinstaller --- .gitignore | 2 ++ README.md | 8 +++++++ main.spec | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + 4 files changed, 65 insertions(+) create mode 100644 main.spec diff --git a/.gitignore b/.gitignore index c67bb3b..c7c5251 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ .idea/ +dist/ +build/ config.json dedo_mouse.log __pycache__/ diff --git a/README.md b/README.md index e7c2a1e..ead0425 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,14 @@ However, licenses of the used libraries (see requirements.txt) differ. For development only: - pylint: [GPL v2.0](https://github.com/rr-/pylint/blob/main/LICENSE) - mypy: [MIT and others](https://github.com/python/mypy/blob/master/LICENSE) +- pyinstaller: [Custom GPL](https://github.com/pyinstaller/pyinstaller/blob/develop/COPYING.txt) + +## Create Executable +Open a console in the virtual environment, then run + +`pyinstaller main.spec` + +This should create a folder named `dist` with the executable. ## Trivia 'Dedo' is Spanish and means 'finger'. diff --git a/main.spec b/main.spec new file mode 100644 index 0000000..9749ec0 --- /dev/null +++ b/main.spec @@ -0,0 +1,54 @@ +# -*- mode: python ; coding: utf-8 -*- + + +block_cipher = None + +# Needed to copy mediapipe files to correct location (https://stackoverflow.com/questions/67887088/issues-compiling-mediapipe-with-pyinstaller-on-macos) +def get_mediapipe_path(): + import mediapipe + mediapipe_path = mediapipe.__path__[0] + return mediapipe_path + +a = Analysis(['src\\main.py'], + pathex=['.\\'], + binaries=[], + datas=[], + hiddenimports=[], + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher, + noarchive=False) +pyz = PYZ(a.pure, a.zipped_data, + cipher=block_cipher) + +# Needed to copy mediapipe files to correct location (https://stackoverflow.com/questions/67887088/issues-compiling-mediapipe-with-pyinstaller-on-macos) +mediapipe_tree = Tree(get_mediapipe_path(), prefix='mediapipe', excludes=["*.pyc"]) +a.datas += mediapipe_tree +a.binaries = filter(lambda x: 'mediapipe' not in x[0], a.binaries) + +exe = EXE(pyz, + a.scripts, + [], + exclude_binaries=True, + name='DedoMouse', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + console=False, + disable_windowed_traceback=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None ) +coll = COLLECT(exe, + a.binaries, + a.zipfiles, + a.datas, + strip=False, + upx=True, + upx_exclude=[], + name='main') diff --git a/requirements.txt b/requirements.txt index e1a874f..14568ff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,3 +9,4 @@ pyside6==6.1.2 rx==3.2.0 pylint==2.9.3 mypy==0.910 +pyinstaller==4.5.1 \ No newline at end of file