pypa/pip · error · PipError
Can not open an editor for a file name containing
Error message
Can not open an editor for a file name containing "
{fname} What it means
Raised by `pip config edit` when the resolved configuration file path contains a double-quote character ("). open_in_editor at configuration.py:240 guards against this because it builds the shell command `f'{editor} "{fname}"'` (configuration.py:248); a quote in the path would break or inject into the shell command. The code comments this should not normally happen unless a username contains one.
Solutions
- Use a username without a double-quote character, or create a separate user account for the install.
- Set PIP_CONFIG_FILE to a safe path without quotes: `export PIP_CONFIG_FILE=/safe/path/pip.conf`.
- Edit the config file manually with a path-safe editor instead of `pip config edit`.
- Avoid `pip config edit`; use `pip config set/get/unset` which do not shell out.
Example fix
// before pip config edit # username contains " char // after export PIP_CONFIG_FILE=/tmp/pip.conf pip config edit
Defensive patterns
Strategy: validation
Validate before calling
# Reject config paths containing a double-quote before editing
import os
def safe_config_edit_path():
from pip._internal.configuration import Configuration
fname = Configuration(get_file_to_edit_via_pip()).get_file_to_edit()
if fname is None:
raise RuntimeError("No config file to edit")
if '"' in fname:
raise ValueError("Config path contains a double-quote; refusing to shell out: %s" % fname)
return fname
Prevention
- Avoid usernames containing double-quote characters.
- Set PIP_CONFIG_FILE to a quote-free path.
- Prefer `pip config set/get/unset` over `pip config edit` to avoid shell-out entirely.
When it happens
Trigger: The OS username (and thus the user config path, e.g. ~/.config/pip/pip.conf or %APPDATA%\pip\pip.ini) contains a " character, and pip config edit resolves that path.
Common situations: An unusual account name containing special characters. This is an edge-case safety guard, not a typical user mistake. The code explicitly invites a pull request to fix the underlying quoting.
Related errors
- Could not determine appropriate file.
- Could not determine editor to use.
- Editor Subprocess exited with exit code
- Got unexpected number of arguments, expected
- Internal Error.
AI-assisted analysis of pypa/pip@f399c37189 (2026-08-08).
Data as JSON: /api/errors/0f7f60951cf9ff5a.
Report an issue: GitHub.
Appendix: 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 f399c37189)