{"id":"4a0b7c806fb1a0dd","repo":"sqlalchemy/alembic","slug":"no-suitable-editor-found-please-set-the-editor","errorCode":null,"errorMessage":"No suitable editor found. Please set the \"EDITOR\" or \"VISUAL\" environment variables","messagePattern":"No suitable editor found\\. Please set the \"EDITOR\" or \"VISUAL\" environment variables","errorType":"exception","errorClass":"OSError","httpStatus":null,"severity":"error","filePath":"alembic/util/editor.py","lineNumber":52,"sourceCode":"    except Exception as exc:\n        raise CommandError(\"Error executing editor (%s)\" % (exc,)) from exc\n\n\ndef _find_editor(environ: Mapping[str, str]) -> str:\n    candidates = _default_editors()\n    for i, var in enumerate((\"EDITOR\", \"VISUAL\")):\n        if var in environ:\n            user_choice = environ[var]\n            if exists(user_choice):\n                return user_choice\n            if os.sep not in user_choice:\n                candidates.insert(i, user_choice)\n\n    for candidate in candidates:\n        path = _find_executable(candidate, environ)\n        if path is not None:\n            return path\n    raise OSError(\n        \"No suitable editor found. Please set the \"\n        '\"EDITOR\" or \"VISUAL\" environment variables'\n    )\n\n\ndef _find_executable(candidate: str, environ: Mapping[str, str]) -> str | None:\n    # Assuming this is on the PATH, we need to determine it's absolute\n    # location. Otherwise, ``check_call`` will fail\n    if not is_posix and splitext(candidate)[1] != \".exe\":\n        candidate += \".exe\"\n    for path in environ.get(\"PATH\", \"\").split(os.pathsep):\n        value = join(path, candidate)\n        if exists(value):\n            return value\n    return None\n\n\ndef _default_editors() -> list[str]:","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/sqlalchemy/alembic/blob/44fb3450330204b222ff05135e1fbbbdb28c44db/alembic/util/editor.py#L34-L70","documentation":"Raised as OSError in _find_editor (editor.py:52) after exhausting every candidate: neither the EDITOR nor VISUAL env var resolves to an existing file/executable, and none of the default editors (sensible-editor, editor, nano, vim, code on posix; code.exe, notepad++.exe, notepad.exe on Windows) are found on PATH. This is a hard stop — Alembic cannot launch any editor.","triggerScenarios":"Running `alembic edit` or `alembic revision` (which may open an editor for the message) on a minimal/containerized system with no editor installed and no EDITOR/VISUAL env var set.","commonSituations":"CI containers, Docker images, or fresh VMs that ship without vim/nano; SSH sessions where the local EDITOR env var isn't forwarded; Windows boxes with neither VS Code nor Notepad++ in PATH.","solutions":["Install any editor and ensure it is on PATH (e.g. `apt-get install nano`).","Export EDITOR (or VISUAL) pointing to an installed editor: `export EDITOR=vim`.","For scripted/non-interactive use, pass the message via -m to `alembic revision` to avoid editor invocation entirely.","On Windows, confirm the editor .exe is in PATH or give EDITOR the full path."],"exampleFix":"# before: no editor installed, no env var\nalembic revision -m 'add col' --edit  # fails\n# after: set EDITOR explicitly\nexport EDITOR=/usr/bin/vim\nalembic revision -m 'add col'\n# or skip the editor\nalembic revision -m 'add col'","handlingStrategy":"validation","validationCode":"import os, shutil\ndef ensure_editor_available() -> str:\n    for var in ('EDITOR', 'VISUAL'):\n        if os.environ.get(var) and (os.path.exists(os.environ[var]) or shutil.which(os.environ[var])):\n            return os.environ[var]\n    for cand in ('nano', 'vim', 'notepad.exe', 'code'):\n        if shutil.which(cand):\n            os.environ['EDITOR'] = cand\n            return cand\n    raise OSError('No editor found; install one or set EDITOR/VISUAL')\n\nensure_editor_available()","typeGuard":null,"tryCatchPattern":"from alembic.util.editor import _find_editor\ntry:\n    _find_editor(os.environ)\nexcept OSError as e:\n    os.environ['EDITOR'] = 'nano'  # or install one\n    # retry","preventionTips":["Install at least one editor (nano/vim) in containers and CI images.","Set EDITOR in your shell rc or Dockerfile ENV.","Forward EDITOR over SSH (ssh -o SendEnv=EDITOR) when editing remotely."],"tags":["alembic","editor","environment","path","command"],"analyzedSha":"44fb3450330204b222ff05135e1fbbbdb28c44db","analyzedAt":"2026-08-04T19:57:10.248Z","schemaVersion":2}