pypa/pip · error · PipError

Can not open an editor for a file name containing " {fname}

Error message

Can not open an editor for a file name containing "
{fname}

What it means

Raised by ConfigurationCommand.open_in_editor when the resolved config file path contains a double-quote character. Because the editor is launched via shell with the filename quoted ('{editor} "{fname}"'), a quote in the path would break the command and is a shell-injection risk, so pip refuses (configuration.py:240). The comment notes this essentially only happens with an unusual username.

Source

Thrown at src/pip/_internal/commands/configuration.py:243

    def print_env_var_values(self) -> None:
        """Get key-values pairs present as environment variables"""
        write_output("%s:", "env_var")
        with indent_log():
            for key, value in sorted(self.configuration.get_environ_vars()):
                env_var = f"PIP_{key.upper()}"
                write_output("%s=%r", env_var, value)

    def open_in_editor(self, options: Values, args: list[str]) -> None:
        editor = self._determine_editor(options)

        fname = self.configuration.get_file_to_edit()
        if fname is None:
            raise PipError("Could not determine appropriate file.")
        elif '"' in fname:
            # This shouldn't happen, unless we see a username like that.
            # If that happens, we'd appreciate a pull request fixing this.
            raise PipError(
                f'Can not open an editor for a file name containing "\n{fname}'
            )

        try:
            subprocess.check_call(f'{editor} "{fname}"', shell=True)
        except FileNotFoundError as e:
            if not e.filename:
                e.filename = editor
            raise
        except subprocess.CalledProcessError as e:
            raise PipError(f"Editor Subprocess exited with exit code {e.returncode}")

    def _get_n_args(self, args: list[str], example: str, n: int) -> Any:
        """Helper to make sure the command got the right number of arguments"""
        if len(args) != n:
            msg = (
                f"Got unexpected number of arguments, expected {n}. "
                f'(example: "{get_prog()} config {example}")'

View on GitHub (pinned to d7d0d0a394)

Solutions

  1. Rename the user account / HOME to a path without double-quotes.
  2. Set HOME (or APPDATA on Windows) to a quote-free directory.
  3. Edit the config file manually with your editor instead of 'pip config edit'.
  4. File a pull request as the source comment suggests - pip could pass the path as an argv element instead of via shell.

Example fix

// before
export HOME='/home/user"q'
pip config edit
// after
export HOME='/home/userq'
pip config edit
Defensive patterns

Strategy: validation

Validate before calling

import os
home = os.environ.get("HOME") or os.environ.get("USERPROFILE") or ""
if '"' in home:
    raise SystemExit("HOME contains a double-quote; pip config edit cannot shell-escape it safely")

Prevention

When it happens

Trigger: The OS username or HOME path contains a " character, which then appears in the user config file path (e.g. ~/.config/pip/pip.conf expanded form). get_file_to_edit returns such a path.

Common situations: A username containing a quote (extremely rare); a HOME environment variable set to a path with a quote; a misconfigured virtualenv root.

Related errors


AI-assisted analysis of pypa/pip@d7d0d0a394 (2026-08-04). Data as JSON: /data/errors/0f7f60951cf9ff5a.json. Report an issue: GitHub.