NWChemEx / NWChemEx/.github

Better Python detection

Open
#27 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.