Skip to content

Instantly share code, notes, and snippets.

@hx2A

hx2A/simple.py Secret

Created March 11, 2022 02:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hx2A/5f664f2934723f47aa05886c99a22c9d to your computer and use it in GitHub Desktop.
Save hx2A/5f664f2934723f47aa05886c99a22c9d to your computer and use it in GitHub Desktop.
Working Pyinstaller Demo
import os
import sys
from pathlib import Path
if hasattr(sys, '_MEIPASS'):
print(getattr(sys, '_MEIPASS'))
else:
print('not in pyinstaller')
import py5_tools
print('cwd =', os.getcwd())
print('__file__ =', __file__)
print(py5_tools.get_classpath())
print(py5_tools.get_jvm_debug_info())
import py5
def setup():
py5.size(200, 200, py5.P2D)
print(py5_tools.get_jvm_debug_info())
def draw():
py5.rect(py5.mouse_x, py5.mouse_y, 10, 10)
py5.run_sketch()
# This spec file is for packaging a Python Sketch into a single directory.
# -*- mode: python ; coding: utf-8 -*-
# https://github.com/pyinstaller/pyinstaller/issues/5363
from PyInstaller.utils.hooks import collect_all, collect_submodules
datas, binaries, hiddenimports = [], [], []
# I don't know what debugpy is or why pyinstaller doesn't seem to work without it. Stackoverflow said to add it...
for lib in ['debugpy', 'py5', 'py5_tools']:
d, b, h = collect_all(lib)
datas.extend(d)
binaries.extend(b)
hiddenimports.extend(h)
# This needs to be the path to your Java 17 installation.
# It will work without it but then your end users will need Java 17 installed.
datas += [('/usr/lib/jvm/java-17-openjdk', 'JAVA_HOME')]
# This is necessary for py5 to find the source code for `setup()`.
# It will work without it but then you need to put your call to `size()` into a `settings()` function instead of `setup()`.
# If your Sketch code has multiple files you don't need to add the others.
datas += [('simple.py', '.')]
# Stackoverflow said to add this also...
hiddenimports += collect_submodules('xmlrpc')
block_cipher = None
a = Analysis(['simple.py'],
pathex=[],
binaries=binaries,
datas=datas,
hiddenimports=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)
exe = EXE(pyz,
a.scripts,
[],
exclude_binaries=True,
name='simple',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True,
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='simple')
# -*- mode: python ; coding: utf-8 -*-
# https://github.com/pyinstaller/pyinstaller/issues/5363
from PyInstaller.utils.hooks import collect_all, collect_submodules
datas, binaries, hiddenimports = [], [], []
for lib in ['debugpy', 'py5', 'py5_tools']:
d, b, h = collect_all(lib)
datas.extend(d)
binaries.extend(b)
hiddenimports.extend(h)
datas += [('/usr/lib/jvm/java-17-openjdk', 'JAVA_HOME')]
datas += [('simple.py', '.')]
hiddenimports += collect_submodules('xmlrpc')
block_cipher = None
a = Analysis(['simple.py'],
pathex=[],
binaries=binaries,
datas=datas,
hiddenimports=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)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='simple',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment