Repository navigation
[tutorials] Let embedded Python use the configured venv on macOS - #23622
Merged
Merged
Conversation
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.
dpiparo
approved these changes
Oct 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
python3in 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)