Skip to content

PY_SITE_PACKAGES_PATH ignores CMAKE_INSTALL_PREFIX, so Python install fails outside a venv #6931

Open

Description

@hjmjohnson

PY_SITE_PACKAGES_PATH defaults to the found interpreter's platlib regardless of CMAKE_INSTALL_PREFIX, so ninja install with ITK_WRAP_PYTHON=ON writes the bindings outside the prefix and fails with "Permission denied" on a system Python (seen on Windows with Python 3.14 under C:/Program Files, #6891). The prefix mismatch is detected at configure but only reported as an install-time WARNING.

Current behavior

Wrapping/Generators/Python/CMakeLists.txt:38-79:

  • sysconfig.get_path('platlib') is stored once as a CACHE STRING; a later change of CMAKE_INSTALL_PREFIX does not recompute it.
  • When CMAKE_INSTALL_PREFIX != sys.prefix, an install(CODE ...) prints a warning, then the install proceeds into the interpreter's site-packages anyway.
  • The failure surfaces at the first bindings file (itkConfig.py), after the C++ install has completed.
Proposed changes
  1. When the prefixes differ, default to the prefix-relative location, ${CMAKE_INSTALL_PREFIX}/<platlib relative to sys.prefix> (e.g. lib/python3.14/site-packages, Lib/site-packages on Windows), and keep the interpreter's platlib only when CMAKE_INSTALL_PREFIX equals sys.prefix (venv, conda, pixi).
  2. Report the decision at configure time with message(STATUS), and replace the install-time WARNING with a configure-time one that names the variable to set.
  3. Check writability of the chosen directory at configure time when it already exists, so the failure is reported before a long build.
  4. Keep PY_SITE_PACKAGES_PATH as the explicit override; document it in Documentation/docs/contributing/module_workflows.md (the install-tree section mentions it as of ENH: Build, test, and wrap external modules against an installed ITK #6891) and in the Python build docs.
  5. Add a CI check that installs with ITK_WRAP_PYTHON=ON into a scratch prefix whose Python is the system interpreter, so the install path is exercised outside a venv.

Item 1 changes where every non-venv Python build installs, so it needs a release note; builds inside a venv, conda, or pixi environment are unaffected.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:Python wrappingPython bindings for a classtype:EnhancementImprovement of existing methods or implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions