Class PythonManager

Constructors

Methods

  • Checks if multiple Python packages are installed.

    Parameters

    • packageNames: string[]

      An array of package names to check for installation.

    • OptionalpythonPathOverride: string

      Optional. The path to the Python executable to use. If not provided, it will use the virtual environment's Python path if available, or fall back to the default Python path.

    Returns Promise<boolean>

    A Promise that resolves to a boolean indicating whether all specified packages are installed (true) or not (false).

  • Create a Python virtual environment.

    Parameters

    • venvPath: string

      The path where the virtual environment will be created.

    • OptionalpythonPathOverride: string

      Optional Python executable path override.

    Returns Promise<string>

  • Delete a virtual environment by removing its directory recursively.

    Parameters

    • venvPath: string

      The path to the virtual environment.

    Returns Promise<void>

  • Ensures that a Python executable is available and sets the pythonPath for the manager. If found on the system, returns its command name. Otherwise, installs Python automatically using pyenv-win (on Windows) or pyenv (on Linux/macOS).

    Parameters

    • version: string = "3.9.1"

      The Python version to ensure (default "3.9.1").

    • pyenvPath: string

      The path to the pyenv executable.

    • OptionalvenvPath: string

      Optional path to the virtual environment. This value is optional but could be required if the process is a ElectronJS application or process executable is located in protected folders on OS. So instead of checking the system folders, use non-protected folders for venv folder and check exsistence of the venv folder.

    Returns Promise<string>

    The path to the Python executable.

  • Retrieves the local Python version set by pyenv.

    This function executes the 'pyenv local' command to get the currently set local Python version. It uses Node.js child process to spawn a shell command and capture its output.

    Returns Promise<string>

    A Promise that resolves with a string representing the local Python version. The version string is trimmed of any leading or trailing whitespace.

    Will reject the promise with an Error if the pyenv command fails to start or exits with a non-zero code.

  • Install a Python package using pip.

    Parameters

    • packageName: string

      The package name to install.

    • OptionalpythonPathOverride: string

      Optional Python executable path override. If not provided, and venvPythonPath is set, it will use venvPythonPath, otherwise default pythonPath.

    Returns Promise<void>

  • Installs multiple Python packages using pip.

    Parameters

    • packageNames: string[]

      An array of package names to install.

    • OptionalpythonPathOverride: string

      Optional Python executable path override. If not provided, and venvPythonPath is set, it will use venvPythonPath, otherwise default pythonPath.

    Returns Promise<void>

    A Promise that resolves when all packages are installed successfully, or rejects if there's an error.

  • Installs Python packages specified in a requirements file using pip.

    Parameters

    • requirementsFilePath: string

      The path to the requirements file containing package specifications.

    • OptionalpythonPathOverride: string

      Optional Python executable path override. If not provided, and venvPythonPath is set, it will use venvPythonPath, otherwise default pythonPath.

    Returns Promise<void>

    A Promise that resolves when all packages from the requirements file are installed successfully, or rejects if there's an error.

  • Install a Python version using pyenv.

    Parameters

    • version: string

      The version string (e.g. "3.9.1")

    Returns Promise<void>

  • Check if a virtual environment exists at the specified path.

    Parameters

    • venvPath: string

      The path to the virtual environment.

    Returns Promise<boolean>

    A promise that resolves to true if the virtual environment exists, and false otherwise.

  • Checks if a specific Python package is installed.

    Parameters

    • packageName: string

      The name of the package to check for installation.

    • OptionalpythonPathOverride: string

      Optional. The path to the Python executable to use. If not provided, it will use the virtual environment's Python path if available, or fall back to the default Python path.

    Returns Promise<boolean>

    A Promise that resolves to a boolean indicating whether the package is installed (true) or not (false).

  • List installed packages (pip freeze).

    Parameters

    • OptionalpythonPathOverride: string

      Optional Python executable path override. If not provided, and venvPythonPath is set, it will use venvPythonPath, otherwise default pythonPath.

    Returns Promise<string[]>

  • List all Python versions installed via pyenv.

    Returns Promise<string[]>

  • Execute arbitrary Python code.

    Parameters

    • code: string

      The Python code to execute.

    • withStream: boolean = false

      If true, streams output live to the console (defaults to false).

    • OptionalpythonPathOverride: string

      Optional Python executable path override. If not provided, and venvPythonPath is set, it will use venvPythonPath, otherwise default pythonPath.

    • OptionalabortSignal: AbortSignal

      Optional AbortSignal to cancel the execution.

    Returns Promise<ExecutionResult>

  • Execute a Python script file with optional live output streaming.

    Parameters

    • filePath: string

      Path to the Python script.

    • args: string[] = []

      Optional arguments to pass to the script.

    • withStream: boolean = false

      If true, streams output live to the console (defaults to false).

    • OptionalpythonPathOverride: string

      Optional Python executable path override. If not provided, and venvPythonPath is set, it will use venvPythonPath, otherwise default pythonPath.

    • OptionalabortSignal: AbortSignal

      Optional AbortSignal to cancel the execution.

    Returns Promise<ExecutionResult>

  • Set the local Python version via pyenv.

    Parameters

    • version: string

      The version to set as local.

    Returns Promise<void>

  • Uninstall a Python package.

    Parameters

    • packageName: string

      The package name to uninstall.

    • OptionalpythonPathOverride: string

      Optional Python executable path override. If not provided, and venvPythonPath is set, it will use venvPythonPath, otherwise default pythonPath.

    Returns Promise<void>

  • Uninstall a Python version using pyenv.

    Parameters

    • version: string

      The version string to uninstall.

    Returns Promise<void>