Skip to content

Instantly share code, notes, and snippets.

@wjladams
Created July 2, 2023 16:36
Show Gist options
  • Save wjladams/f1b4fe28410f20556ac6cb745d6af07b to your computer and use it in GitHub Desktop.
Save wjladams/f1b4fe28410f20556ac6cb745d6af07b to your computer and use it in GitHub Desktop.
Using pyinstaller
#!/usr/bin/env python
# This is a simple script that needs the tkinter and pandas libraries
# to test pyinstaller correctly wrapping these libraries.ex
import pandas as pd
from tkinter.filedialog import askopenfilename
filename = askopenfilename(initialdir="../data")
if filename is None:
exit(0)
df = pd.read_excel(filename)
print(df.head())
# -*- mode: python ; coding: utf-8 -*-
# This was autogenerated by running
# pyinstaller example.py
# Except it reached a recursion limit and suggested adding the following line
# and then running
# pyinstaller example.spec
# instead
import sys ; sys.setrecursionlimit(sys.getrecursionlimit() * 5)
block_cipher = None
a = Analysis(
['example.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)
exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name='rmme',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True,
disable_windowed_traceback=False,
argv_emulation=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='rmme',
)

Instructions

  1. Make sure to have pyinstaller installed, i.e. run pip install pyinstaller, or in a conda environment you can run conda install pyinstaller
  2. Download example.py and example.spec into the same directory
  3. From that directory run pyinstaller example.spec (note, run on the spec file)
  4. That will create a subdirectory path dist/example go there and you can run the example

Note: This directory may contain other libraries, depending on your operating system, so it probably can only be run from that directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment