Class VirtualEnvManager

Constructors

Methods

  • Create a Python virtual environment.

    Parameters

    • venvPath: string

      The path where the virtual environment will be created.

    • pythonPath: string = "python"

      The Python executable to use (defaults to "python").

    Returns Promise<string>

  • Delete a virtual environment by removing its directory recursively.

    Parameters

    • venvPath: string

      The path to the virtual environment.

    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.

    This function uses the fsPromises.access method to check if the virtual environment directory exists. If the directory exists, the function resolves to true; otherwise, it resolves to false.

    const venvManager = new VirtualEnvManager();
    const venvPath = "path/to/virtual/environment";

    try {
    const venvExists = await venvManager.existsVenv(venvPath);
    if (venvExists) {
    console.log("Virtual environment exists.");
    } else {
    console.log("Virtual environment does not exist.");
    }
    } catch (error) {
    console.error("Error checking virtual environment:", error);
    }