python/cpython · warning
%s
Error message
%s
What it means
This is the getpath module's warn() implementation: a Python-level warning string forwarded to C stderr by the frozen getpath code that locates the interpreter's home/prefix at startup. The '%s' is just the printf placeholder — the actual message is whatever getpath passed (e.g. 'Could not find platform independent libraries', 'Consider setting $PYTHONHOME...', prefix warnings). Seeing it means path detection during startup had to complain.
Source
Thrown at Modules/getpath.c:594
{"isxfile", getpath_isxfile, METH_VARARGS, NULL},
{"joinpath", getpath_joinpath, METH_VARARGS, NULL},
{"readlines", getpath_readlines, METH_VARARGS, NULL},
{"realpath", getpath_realpath, METH_VARARGS, NULL},
{NULL, NULL, 0, NULL}
};
/* Two implementations of warn() to use depending on whether warnings
are enabled or not. */
static PyObject *
getpath_warn(PyObject *Py_UNUSED(self), PyObject *args)
{
PyObject *msgobj;
if (!PyArg_ParseTuple(args, "U", &msgobj)) {
return NULL;
}
fprintf(stderr, "%s\n", PyUnicode_AsUTF8(msgobj));
Py_RETURN_NONE;
}
static PyObject *
getpath_nowarn(PyObject *Py_UNUSED(self), PyObject *args)
{
Py_RETURN_NONE;
}
static PyMethodDef getpath_warn_method = {"warn", getpath_warn, METH_VARARGS, NULL};
static PyMethodDef getpath_nowarn_method = {"warn", getpath_nowarn, METH_VARARGS, NULL};
/* Add the helper functions to the dict */
static int
funcs_to_dict(PyObject *dict, int warnings)
{View on GitHub (pinned to bc6749cc3b)
Solutions
- Set PYTHONHOME to the correct prefix (the dir containing lib/pythonX.Y) or unset a stale one
- Reinstall the Python build in a location matching its configured prefix, or rebuild with ./configure --prefix matching the install dir
- For embedded interpreters, configure the home via PyConfig.home / path config before initialization
- Check for leftover PYTHONHOME/PYTHONPATH env vars from virtualenvs or containers layered onto the image
Defensive patterns
Strategy: validation
Validate before calling
# shell: verify the install layout before relying on it # test -x "$PYTHONHOME/bin/python3" || echo 'PYTHONHOME is wrong' # env | grep -E 'PYTHON(HOME|PATH)' # find stale vars
Prevention
- Set PYTHONHOME only when the interpreter was relocated, and point it at the real prefix
- Unset PYTHONHOME/PYTHONPATH from old virtualenvs when switching interpreters
- Rebuild relocated Pythons with --prefix matching their final install directory
- Validate deployment images by launching `python3 -c 'import sys; print(sys.prefix)'` and comparing to expectation
When it happens
Trigger: Interpreter startup where the calculated prefix/exec_prefix does not match the build-time expectations, PYTHONHOME is wrong, or the stdlib zip/libdir cannot be found — getpath raises warnings via sys.warn (this function when warnings are enabled).
Common situations: Moving or copying a CPython installation to another directory without setting PYTHONHOME; broken virtualenvs/pyenv shims pointing at a deleted prefix; Linux distributions relocating binaries; embedded interprements with misconfigured search paths. Python may still start but import of stdlib can misbehave.
Related errors
- Error setting LC_CTYPE, skipping C locale coercion\n
- Python detected LC_CTYPE=C: LC_CTYPE coerced to %.20s (set a
- Warning: failed setting the LC_CTYPE environment variable to
- posix_spawnattr_setbinpref failed to copy\n
- Argument expected for the %ls options\n
AI-assisted analysis of python/cpython@bc6749cc3b (2026-08-14).
Data as JSON: /api/errors/3f7ab8865cff16cd.
Report an issue: GitHub.