Better Python detection
Nobody has claimed this yet.
- Dominant language
- Dockerfile
- Stars
- 1
- Forks
- 2
- Avg merge
- 22m
- Merged PRs (30d)
- 4
Description
Despite running my build in a Python virtual environment, created by /usr/bin/python3, CMake somehow manages to find /usr/bin/python3.11 (FWIW /usr/bin/ptyon3 is a sym link of 3.8). IMHO it should first find the virtual environment version (arguably that's the whole point of the virtual environment), but it would also be understandable if it found /usr/bin/python3 (albeit less desirable). The fact that it found python3.11 is unexpected (at least to me).
Here is where Python is detected. Off the top of my head I'm not sure what needs to change to make the detection more reasonable.
Edit: it looks like a workaround is for the user to add set(Python3_FIND_VIRTUALENV ONLY) to their toolchain. Maybe we can resolve this issue by setting Python3_FIND_VIRTUALENV to FIRST (if it's not set) before calling find_package(Python3)?
Edit 2: CMake seems to still be finding /usr/bin/python3.11 for me, even after setting Python3_FIND_VIRTUALENV to ONLY. Hmm...
Edit 3: Tried adding set(Python3_ROOT_DIR /path/to/venv) to my toolchain.cmake and still am getting /usr/bin/python3.11...
Edit 4: Finally got it to work by adding set(Python3_EXECUTABLE /path/to/venv/bin/python3) in my toolchain file.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with cmake/FindCppyy.cmake at the Python detection call around line 11, then reproduce the lookup using a virtual environment created by /usr/bin/python3 and the reported toolchain settings. Compare the selected interpreter with the virtual environment executable and document a change that reliably selects the intended Python interpreter.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, python
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100