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

  1. Set PYTHONHOME to the correct prefix (the dir containing lib/pythonX.Y) or unset a stale one
  2. Reinstall the Python build in a location matching its configured prefix, or rebuild with ./configure --prefix matching the install dir
  3. For embedded interpreters, configure the home via PyConfig.home / path config before initialization
  4. 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

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


AI-assisted analysis of python/cpython@bc6749cc3b (2026-08-14). Data as JSON: /api/errors/3f7ab8865cff16cd. Report an issue: GitHub.