oraios/serena · critical · RuntimeError

PowerShell Core (pwsh) is not installed or not in PATH. Plea

Error message

PowerShell Core (pwsh) is not installed or not in PATH. Please install PowerShell 7+ from https://github.com/PowerShell/PowerShell

What it means

The PowerShell language server runs on PowerShell Editor Services, which requires PowerShell 7+ (pwsh) as the host runtime. _setup_runtime_dependency first resolves pwsh via _get_pwsh_path (PATH lookup plus a few well-known install locations); if nothing is found, it raises this RuntimeError during __init__. The library deliberately does not download pwsh itself.

Source

Thrown at src/solidlsp/language_servers/powershell_language_server.py:174

            raise RuntimeError(f"Failed to find Start-EditorServices.ps1 after extraction at {start_script}")

        log.info(f"PowerShell Editor Services installed at: {install_dir}")
        return str(start_script)

    @classmethod
    def _setup_runtime_dependency(cls, solidlsp_settings: SolidLSPSettings) -> tuple[str, str, str]:
        """
        Check if required PowerShell runtime dependencies are available.
        Downloads PowerShell Editor Services if not present.

        Returns:
            tuple: (pwsh_path, start_script_path, bundled_modules_path)

        """
        # Check for PowerShell Core
        pwsh_path = cls._get_pwsh_path()
        if not pwsh_path:
            raise RuntimeError(
                "PowerShell Core (pwsh) is not installed or not in PATH. "
                "Please install PowerShell 7+ from https://github.com/PowerShell/PowerShell"
            )

        # Check for PowerShell Editor Services
        pses_path = cls._get_pses_path(solidlsp_settings)
        if not pses_path:
            log.info("PowerShell Editor Services not found. Downloading...")
            pses_path = cls._download_pses(solidlsp_settings)

        # The bundled modules path is the directory containing PowerShellEditorServices
        bundled_modules_path = str(Path(pses_path).parent)
        psscriptanalyzer_version = solidlsp_settings.get_ls_specific_settings(LanguageServerId.POWERSHELL).get(
            "psscriptanalyzer_version", PSSCRIPTANALYZER_VERSION
        )
        psscriptanalyzer_path = Path(bundled_modules_path) / "PSScriptAnalyzer" / psscriptanalyzer_version
        if not psscriptanalyzer_path.exists():
            log.info(f"PSScriptAnalyzer {psscriptanalyzer_version} not found. Installing...")

View on GitHub (pinned to 7fcbca7e62)

Solutions

  1. Install PowerShell 7+ from https://github.com/PowerShell/PowerShell for your OS.
  2. Ensure the pwsh binary's directory is on your PATH (echo $env:PATH / echo $PATH) or symlink it, e.g. ln -s /opt/microsoft/powershell/7/pwsh /usr/local/bin/pwsh.
  3. On Windows, install the MSI (adds pwsh to PATH) rather than relying on Windows PowerShell 5.1.
  4. In CI, use a setup step (e.g. PowerShell action or winget/apt/brew install powershell) before creating the server.

Example fix

# before: only powershell.exe (5.1) present on Windows PATH
# after: install PowerShell 7 and verify
winget install --id Microsoft.PowerShell
pwsh -v   # or: Get-Command pwsh
Defensive patterns

Strategy: validation

Validate before calling

import shutil
if shutil.which('pwsh') is None:
    raise SystemExit(
        'PowerShell 7+ (pwsh) is required. Install from '
        'https://github.com/PowerShell/PowerShell and ensure it is on PATH.'
    )

Try / catch

try:
    server = SolidLanguageServer.create('powershell', repo_root, settings)
except RuntimeError as e:
    if 'PowerShell Core (pwsh) is not installed' in str(e):
        raise EnvironmentError(
            'Install PowerShell 7+ first: https://github.com/PowerShell/PowerShell'
        ) from e
    raise

Prevention

When it happens

Trigger: Constructing the PowerShell language server (SolidLanguageServer.create for 'powershell') on a machine where pwsh is neither on PATH nor at the hardcoded locations (/usr/bin/pwsh, /usr/local/bin/pwsh, /opt/homebrew/bin/pwsh, /opt/microsoft/powershell/7/pwsh, ~/.dotnet/tools/pwsh, or the Windows Program Files path) — i.e. only Windows PowerShell 5.1 (powershell.exe) is installed, or pwsh was installed via snap/other package managers that don't add these paths.

Common situations: Fresh Linux/macOS/CI containers without PowerShell; having only built-in Windows PowerShell 5.1; installing pwsh via a method that doesn't update PATH; a venv/docker image where PATH was modified after install.

Related errors


AI-assisted analysis of oraios/serena@7fcbca7e62 (2026-08-29). Data as JSON: /api/errors/07c7f337023b077e. Report an issue: GitHub.