Skip to content

[tutorials] Let embedded Python use the configured venv on macOS - #23622

Merged
guitargeek merged 1 commit into
root-project:masterfrom
guitargeek:pythonenv
Oct 6, 2026
Merged

guitargeek merged 1 commit into
root-project:masterfrom
guitargeek:pythonenv

Conversation

@guitargeek

@guitargeek guitargeek commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

On macOS, a Python interpreter that is embedded in a C++ process doesn't use the virtual environment that the configured Python executable belongs to, even if that environment is activated: CPython takes the running binary as the executable and never finds the pyvenv.cfg of the environment. On Linux, it finds python3 in the PATH instead.

Therefore, C++ tutorials that embed Python, don't find Python modules that are only installed in the virtual environment, even though CMake found them with the Python executable of that environment and enabled the tutorials.

Set PYTHONEXECUTABLE to the configured Python executable for the tutorials on macOS, which makes the embedded interpreter use the same environment.

This PR doesn't fix anything in master, but backporting this in needed to fix failures in the 6.40 nightlies (see #23623)

On macOS, a Python interpreter that is embedded in a C++ process doesn't
use the virtual environment that the configured Python executable
belongs to, even if that environment is activated: CPython takes the
running binary as the executable and never finds the pyvenv.cfg of the
environment. On Linux, it finds `python3` in the PATH instead.

Therefore, C++ tutorials that embed Python, don't find Python modules
that are only installed in the virtual environment, even though CMake
found them with the Python executable of that environment and enabled
the tutorials.

Set PYTHONEXECUTABLE to the configured Python executable for the
tutorials on macOS, which makes the embedded interpreter use the same
environment.
@guitargeek
guitargeek merged commit a3f3920 into root-project:master Oct 6, 2026
26 of 29 checks passed
@guitargeek
guitargeek deleted the pythonenv branch October 6, 2026 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants