CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pyinstaller

PyInstaller bundles a Python application and all its dependencies into a single package.

Pending
Overview
Eval results
Files

cli-utilities.mddocs/

CLI Utilities

PyInstaller provides several command-line utilities for inspecting archives, analyzing dependencies, and managing version information. These tools are installed as console scripts and can be used independently of the main PyInstaller build process.

Capabilities

Archive Viewer

Interactive tool for inspecting the contents of PyInstaller archives.

# Console script
pyi-archive_viewer [archive_path]
def run():
    """
    Launch interactive archive viewer for PyInstaller archives.
    
    The archive viewer provides commands to:
    - List archive contents
    - Extract files from archives  
    - View file information and dependencies
    - Navigate directory structures within archives
    
    Interactive commands:
        o <filename>  - Open and display file contents
        x <filename>  - Extract file to current directory
        s             - Search for files by name pattern
        q             - Quit the viewer
    
    Example usage:
        $ pyi-archive_viewer dist/myapp/myapp.exe
        ? help
        ? ls
        ? o PYZ-00.pyz
        ? x somefile.py
    """

Binary Dependency Analyzer

Analyzes binary dependencies of executables and shared libraries.

# Console script  
pyi-bindepend [options] executable_or_library
def run():
    """
    Analyze binary dependencies of executables and libraries.
    
    Discovers and reports all shared library dependencies, helping
    identify missing dependencies or version conflicts.
    
    Options:
        --upx-dir DIR     Directory containing UPX executable
        
    Output includes:
    - Direct dependencies
    - Recursive dependency tree
    - Missing or unresolved dependencies
    - Library search paths
    
    Example usage:
        $ pyi-bindepend dist/myapp/myapp.exe
        $ pyi-bindepend --upx-dir /usr/local/bin dist/myapp/_internal/numpy.libs/libopenblas.so
    """

Version Information Extractor

Extracts version information from Windows executables and DLLs.

# Console script (Windows only)
pyi-grab_version [options] executable_path
def run():
    """
    Extract version information from Windows executables.
    
    Reads version resources from PE files and outputs in format
    suitable for use with pyi-set_version or --version-file option.
    
    Options:
        -o, --out FILE    Output file for version information
        
    Extracted information includes:
    - File version numbers
    - Product version numbers  
    - Company information
    - File description
    - Copyright information
    - Original filename
    
    Example usage:
        $ pyi-grab_version some_app.exe
        $ pyi-grab_version -o version_info.txt target.exe
    """

Spec File Generator

Generates .spec files without building the executable.

# Console script
pyi-makespec [options] script [script ...]
def run():
    """
    Generate PyInstaller .spec files without building.
    
    Creates customizable .spec files that can be edited before building.
    Accepts the same options as the main pyinstaller command but only
    generates the specification file.
    
    Common options:
        --onefile         Generate spec for one-file bundle
        --onedir          Generate spec for one-directory bundle
        --windowed        Generate spec for windowed application
        --name NAME       Assign custom name to executable
        --icon ICON       Add application icon
        --add-data SRC:DEST  Add data files
        --hidden-import MODULE  Add hidden imports
        
    The generated .spec file can then be customized and built with:
        pyinstaller myapp.spec
        
    Example usage:
        $ pyi-makespec --onefile --windowed --name MyApp main.py
        $ pyi-makespec --add-data "config/*:config" --icon app.ico script.py
    """

Version Information Setter

Sets version information on Windows executables.

# Console script (Windows only)  
pyi-set_version version_info_file executable_path
def run():
    """
    Set version information on Windows executables.
    
    Embeds version resources into PE files using version information
    from a text file (typically created by pyi-grab_version).
    
    Args:
        version_info_file (str): Path to version information file
        executable_path (str): Path to executable to modify
        
    The version information file format contains:
    - VSVersionInfo structure
    - StringFileInfo with language/codepage
    - VarFileInfo with translations
    
    Example usage:
        $ pyi-set_version version_info.txt dist/myapp.exe
        
    Version info file example:
        VSVersionInfo(
            ffi=FixedFileInfo(
                filevers=(1, 0, 0, 0),
                prodvers=(1, 0, 0, 0),
                ...
            ),
            kids=[
                StringFileInfo([
                    StringTable('040904B0', [
                        StringStruct('CompanyName', 'My Company'),
                        StringStruct('FileDescription', 'My Application'),
                        ...
                    ])
                ]),
                ...
            ]
        )
    """

Usage Examples

Archive Inspection Workflow

# Build application
pyinstaller --onefile myapp.py

# Inspect the generated executable
pyi-archive_viewer dist/myapp.exe

# Interactive session:
# ? ls                    # List contents
# ? o PYZ-00.pyz         # Open Python archive
# ? s numpy              # Search for numpy files
# ? x mymodule.pyc       # Extract compiled module
# ? q                    # Quit

Dependency Analysis Workflow

# Analyze dependencies of built executable
pyi-bindepend dist/myapp/myapp.exe

# Check specific library dependencies
pyi-bindepend dist/myapp/_internal/numpy/.libs/libopenblas.so

# Analyze with UPX
pyi-bindepend --upx-dir /usr/local/bin dist/myapp.exe

Version Management Workflow (Windows)

# Extract version info from existing executable
pyi-grab_version -o version_template.txt some_reference.exe

# Edit version_template.txt as needed
# ...

# Build application
pyinstaller myapp.py

# Apply version information
pyi-set_version version_template.txt dist/myapp.exe

# Verify version was applied
pyi-grab_version dist/myapp.exe

Custom Spec File Workflow

# Generate customizable spec file
pyi-makespec --onefile --windowed --name MyApplication \
    --icon assets/icon.ico \
    --add-data "config/*:config" \
    --add-data "templates/*:templates" \
    --hidden-import pkg_resources.py2_warn \
    src/main.py

# Edit MyApplication.spec file to add custom logic
# Add conditional imports, modify file collection, etc.

# Build from customized spec
pyinstaller MyApplication.spec

Advanced Archive Analysis

# Create archive viewer session script
cat > analyze_archive.txt << EOF
ls
o PYZ-00.pyz
ls *.py*
s requests
x requests/__init__.pyc
q
EOF

# Run automated analysis
pyi-archive_viewer dist/myapp.exe < analyze_archive.txt

Integration with Build Process

The CLI utilities can be integrated into automated build workflows:

Build Script Example

#!/bin/bash
# build_and_analyze.sh

set -e

echo "Building application..."
pyinstaller --clean myapp.spec

echo "Analyzing dependencies..."
pyi-bindepend dist/myapp/myapp > dependencies.txt

echo "Extracting archive contents..."
echo -e "ls\nq" | pyi-archive_viewer dist/myapp/myapp.exe > archive_contents.txt

echo "Setting version information..."
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
    pyi-set_version version_info.txt dist/myapp/myapp.exe
fi

echo "Build complete. Check dependencies.txt and archive_contents.txt for analysis results."

CI/CD Integration

# .github/workflows/build.yml
- name: Build with PyInstaller
  run: pyinstaller --onefile myapp.py

- name: Analyze dependencies  
  run: pyi-bindepend dist/myapp > dependencies.txt

- name: Verify archive contents
  run: echo -e "ls\nq" | pyi-archive_viewer dist/myapp > contents.txt

- name: Upload analysis artifacts
  uses: actions/upload-artifact@v3
  with:
    name: build-analysis
    path: |
      dependencies.txt
      contents.txt

Common Use Cases

Debugging Missing Dependencies

# Check what's actually bundled
pyi-archive_viewer dist/myapp.exe
# Look for missing modules in PYZ archive

# Analyze system dependencies
pyi-bindepend dist/myapp/_internal/libsomething.so
# Identify missing system libraries

Size Optimization Analysis

# List all bundled files with sizes
echo -e "ls -l\nq" | pyi-archive_viewer dist/myapp.exe | grep -E "^\s*\d+"
# Identify large files for exclusion

# Check if UPX compression is working
pyi-bindepend --upx-dir /usr/bin dist/myapp.exe

Version Information Management

# Extract template from similar application
pyi-grab_version reference_app.exe -o version_template.txt

# Customize version info programmatically
sed -i 's/Reference App/My Application/g' version_template.txt

# Apply to built executable
pyi-set_version version_template.txt dist/myapp.exe

Install with Tessl CLI

npx tessl i tessl/pypi-pyinstaller

docs

cli-interface.md

cli-utilities.md

hook-development.md

index.md

platform-features.md

spec-file-classes.md

tile.json