This function validates the Python installation, checks for required modules, and installs dependencies if needed. It's designed to be called before any tcrClustR functions that rely on Python (e.g., RunTcrdist3, .FormatMetadata).

SetupPythonEnvironment(
  pythonExecutable = NULL,
  installMissing = TRUE,
  useRequirementsTxt = TRUE,
  verbose = TRUE
)

Arguments

pythonExecutable

Path to the Python executable. If NULL (default), will use reticulate::py_exe() or fall back to system Python3.

installMissing

Logical. If TRUE (default), will attempt to install missing Python packages. If FALSE, will only validate and report missing packages.

useRequirementsTxt

Logical. If TRUE (default), will attempt to install dependencies from requirements.txt if available. If FALSE, will install individual packages.

verbose

Logical. If TRUE, will display detailed progress messages.

Value

Invisible logical: TRUE if all dependencies are available, FALSE otherwise.

Details

This function performs the following steps:

  1. Validates Python executable exists and is functional

  2. Checks for required Python modules: tcrdist3, pandas, numpy, rpy2

  3. If installMissing=TRUE, installs missing packages via pip

  4. Returns status of dependency availability

The function uses requirements.txt for dependency management when available, and falls back to individual package installation if not found.

Examples

if (FALSE) { # \dontrun{
# Check and install Python dependencies
SetupPythonEnvironment()

# Just validate without installing
SetupPythonEnvironment(installMissing = FALSE)

# Use specific Python executable
SetupPythonEnvironment(pythonExecutable = "/usr/bin/python3")
} # }