Skip to content

Updated modules in find_package command for Python3 - #933

Merged
casperdcl merged 5 commits into
SyneRBI:masterfrom
NicoleJurjew:update_find_package
Mar 25, 2025
Merged

Updated modules in find_package command for Python3#933
casperdcl merged 5 commits into
SyneRBI:masterfrom
NicoleJurjew:update_find_package

Conversation

@NicoleJurjew

Copy link
Copy Markdown
Contributor

No description provided.

@KrisThielemans KrisThielemans linked an issue Oct 3, 2024 that may be closed by this pull request
@KrisThielemans KrisThielemans self-assigned this Oct 3, 2024
@KrisThielemans

Copy link
Copy Markdown
Member

https://cmake.org/cmake/help/latest/module/FindPythonInterp.html deprecated since 3.12, while we require 3.16.2.

Current change is minimal. We probably should pass Python_EXECUTABLE as opposed to PYTHON_EXECUTABLE to dependencies, but this needs a check which ones we use. Probably easiest to pass both. I think we should no longer attempt to pass include and other paths, and let CMake sort it out.

Comment thread SuperBuild.cmake Outdated
Comment thread SuperBuild.cmake Outdated
@KrisThielemans

Copy link
Copy Markdown
Member

Need to update how we look for cython I guess

[100%] Generating build/timestamp
Traceback (most recent call last):
  File "/home/runner/work/SIRF-SuperBuild/SIRF-SuperBuild/build/builds/TomoPhantom/build/Wrappers/Python/setup.py", line 19, in <module>
    from Cython.Distutils import build_ext
ModuleNotFoundError: No module named 'Cython'
gmake[5]: *** [Wrappers/Python/CMakeFiles/PythonWrapper.dir/build.make:76: Wrappers/Python/build/timestamp] Error 1
gmake[4]: *** [CMakeFiles/Makefile2:157: Wrappers/Python/CMakeFiles/PythonWrapper.dir/all] Error 2
gmake[3]: *** [Makefile:136: all] Error 2
gmake[2]: *** [CMakeFiles/TomoPhantom.dir/build.make:86: builds/TomoPhantom/stamp/TomoPhantom-build] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:755: CMakeFiles/TomoPhantom.dir/all] Error 2

This error is different from why I saw in #932 but it's possible that @NicoleJurjew only saw the Tomophantom error when using this branch I guess.

@NicoleJurjew

Copy link
Copy Markdown
Contributor Author

With the suggested changes, the PYTHONPATH isn't exported correctly.

I think some changes need to be done here, as well:
https://github.com/SyneRBI/SIRF-SuperBuild/blob/5f1a7f498bf6f41551c19eb53798b5d33af43eec/SuperBuild.cmake#L366C1-L386C8

@KrisThielemans

Copy link
Copy Markdown
Member

that's a bit strange. What is the content of env_sirf.sh etc then? Can you just do a

message(STATUS "PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}")

before those statement to check what it is?

@NicoleJurjew

Copy link
Copy Markdown
Contributor Author

This is the content of env_sirf.sh:
grafik

Where will that message be written to then? Thanks!

@paskino

paskino commented Feb 13, 2025

Copy link
Copy Markdown
Contributor

@casperdcl
casperdcl force-pushed the update_find_package branch 2 times, most recently from 3f09077 to f5d9c0c Compare March 20, 2025 12:49
@casperdcl

Copy link
Copy Markdown
Member

@KrisThielemans

Copy link
Copy Markdown
Member

This was all discussed in #937. I've contributed a PR to Gadgetron. However, moving on with Gadgetron created a lot of other problems. So @paskino and I decided to wait with that, and just fix Ubuntu 22.04. This is done in #943. So suggestion therefore is to finish #943, merge it, and merge that back on here.

@KrisThielemans KrisThielemans left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check if the dependencies indeed accept Python3_EXECUTABLE. In any case, I'm fairly sure this needs to be Python_EXECUTABLE. Easiest might be to pass both of course, although that's a bit ugly.

Also, in SIRF and STIR, we have a "backwards compatible" line to set Python_EXECUTABLE if PYTHON_EXECUTABLE is set. Maybe no longer need it?

@KrisThielemans

Copy link
Copy Markdown
Member

@casperdcl I've merged #943.

Note that we'll also need to update CHANGES.md here.

@casperdcl
casperdcl force-pushed the update_find_package branch from f5d9c0c to 15b6504 Compare March 21, 2025 10:10
Comment thread SuperBuild.cmake
Comment thread SuperBuild.cmake Outdated
Comment thread SuperBuild/External_NiftyPET.cmake Outdated
Comment on lines +71 to +72
-DPython_EXECUTABLE=${NiftyPET_PYTHON_EXECUTABLE}
-DPython3_Executable=${NiftyPET_PYTHON_EXECUTABLE}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that we are stuck to NiftyPET 2. Are you sure this is ok?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why? Current NiftyPET is Python3 only.

@KrisThielemans KrisThielemans Mar 21, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We currently only use NiftyPET via STIR, but that all happens on the C++ front. NiftyPET3 no longer has the appropriate libraries, and I have no energy for it.

See UCL/STIR#1294 to jog your memory :-)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be worthwile wrapping NiftyPET in CIL instead, but it's nowhere on my (our?) list of priorities.

Comment thread VirtualBox/scripts/UPDATE_functions.sh Outdated
Comment thread SuperBuild/External_ROOT.cmake Outdated
Comment thread SuperBuild.cmake Outdated
Comment thread SuperBuild.cmake Outdated
@KrisThielemans

KrisThielemans commented Mar 21, 2025

Copy link
Copy Markdown
Member

There seem to be 2 different Python versions used in the CIL install, resulting in the cil not being found at import. There are 2 causes for this.

For the SB, CMake finds a surprising version (which is then passed on)

Found Python: /opt/hostedtoolcache/Python/3.10.12/x64/bin/python3.10 (found version "3.10.12") found components: Interpreter Development Development.Module Development.Embed
Found Python_EXECUTABLE=/opt/hostedtoolcache/Python/3.10.12/x64/bin/python3.10

The CMake strategy for selecting a python version is still far too complicated/error-prone. I suggest therefore to explicitly set
Python_EXECUTABLE=${which python} in the Action.

In addition, it looks like the CIL version that is being built (I only checked with DEVEL_BUILD=OFF) uses old-style:

-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython3.10.so (found version "3.10.12")
-- Found PYTHON_EXECUTABLE=/home/runner/virtualenv/bin/python

I think therefore we need to add PYTHON_EXECUTABLE to the PYTHONLIBS_CMAKE_ARGS variable. That's safest in any case.

@casperdcl
casperdcl force-pushed the update_find_package branch from 9e2e844 to c4bacd6 Compare March 21, 2025 12:36
@KrisThielemans

Copy link
Copy Markdown
Member
ModuleNotFoundError: No module named 'Cython'

when building TomoPhantom. Not sure why this happens now? Wrong python used? TBH, We shouldn't really build TomoPhantom as part of our CI I think. @paskino ?

Run actions/upload-artifact@v4
  with:
    name: build_log_files-ubuntu-22.04-gcc9-Release-DEVEL=OFF
...
Error: Failed to CreateArtifact: Received non-retryable error: Failed request: (409) Conflict: an artifact with this name already exists on the workflow run

I guess we have a problem with the naming somewhere.

@casperdcl
casperdcl force-pushed the update_find_package branch 2 times, most recently from 2e56611 to 9fa54cf Compare March 24, 2025 12:19
@casperdcl

casperdcl commented Mar 24, 2025

Copy link
Copy Markdown
Member

TomoPhantom v2.0.0 (and also the slightly more recent v3.0) doesn't specify build deps. Its setup.py needs Cython & numpy. Adding them to the build step works.

Current test failures due to lack of CIL deps... CIL:scripts/requirements-test.yml are not included in CIL:pyproject.toml and I think they should be. I've opened TomographicImaging/CIL#2116

Comment thread SuperBuild.cmake Outdated
Comment thread SuperBuild.cmake Outdated
@casperdcl
casperdcl force-pushed the update_find_package branch 2 times, most recently from ed81a12 to 74fd9cb Compare March 24, 2025 16:20
@KrisThielemans

Copy link
Copy Markdown
Member

For the SB, CMake finds a surprising version (which is then passed on)

Found Python: /opt/hostedtoolcache/Python/3.10.12/x64/bin/python3.10 (found version "3.10.12") found components: Interpreter Development Development.Module Development.Embed
Found Python_EXECUTABLE=/opt/hostedtoolcache/Python/3.10.12/x64/bin/python3.10

The CMake strategy for selecting a python version is still far too complicated/error-prone. I suggest therefore to explicitly set Python_EXECUTABLE=${which python} in the Action.

This is still the case, hence the failures.

@casperdcl
casperdcl force-pushed the update_find_package branch 2 times, most recently from 3569455 to 72b5111 Compare March 25, 2025 11:57
@casperdcl

casperdcl commented Mar 25, 2025

Copy link
Copy Markdown
Member

Ah I finally understood; you don't want to use the system Python.

TL;DR we need to unset the cmake helpers defined by actions/setup-python.

@casperdcl
casperdcl force-pushed the update_find_package branch from cd45e61 to 1cbc258 Compare March 25, 2025 12:25
@KrisThielemans

Copy link
Copy Markdown
Member

Ah I finally understood; you don't want to use the system Python.

TL;DR we need to unset the cmake helpers defined by actions/setup-python.

pretty confusing... I don't care which python is being used here, but obviously we should always use the same. As we seem to be using setup-python with pip, and then create a venv, we should be using that one. I guess that's what you did now, so ... great.

Sadly, some zenodo download issues ATM.

@KrisThielemans KrisThielemans left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh. still need to update CHANGES.md!

@casperdcl
casperdcl merged commit fda719d into SyneRBI:master Mar 25, 2025
@KrisThielemans

Copy link
Copy Markdown
Member

Success! Thanks @casperdcl . however, can you now have a different PR to update CHANGES.md, saying that we've switched to FindPython (maybe a link), and that they should use Python_EXECUTABLE or any other variables as indicated in the CMake doc? (Sorry, I shouldn't have approved the PR :-))

@casperdcl

Copy link
Copy Markdown
Member

Already updated the changelog; feel free to update further

@KrisThielemans

Copy link
Copy Markdown
Member

Sorry. Confused. Which changelog?

@casperdcl

Copy link
Copy Markdown
Member

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.

Need to switch to use CMake's FindPython

4 participants