Skip to content

ENH: Add script to install python packages locally - #978

Open
axel-grc wants to merge 2 commits into
RTKConsortium:mainfrom
axel-grc:PythonInstall
Open

axel-grc wants to merge 2 commits into
RTKConsortium:mainfrom
axel-grc:PythonInstall

Conversation

@axel-grc

Copy link
Copy Markdown
Collaborator

No description provided.

@axel-grc
axel-grc requested a review from SimonRit August 24, 2026 07:59

@SimonRit SimonRit left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice, just two small questions below

Comment thread utilities/build_rtk_python.sh Outdated
#
# All paths below can be overridden via environment variables.

set -euo pipefail

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

-eu look good. Why set -o pipefail? There is no pipe here as far as I can tell.
I would also consider adding -x

Comment thread utilities/build_rtk_python.sh Outdated
--config-settings=cmake.define.ITK_USE_PYTHON_LIMITED_API=OFF
)
echo "==> Installing RTK Python package (editable)"
rm -rf "$RTK_PIP_BUILD_DIR"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we keep the build directory to avoid recompiling from scratch for C++ changes?

@SimonRit SimonRit added this to the RTK 3.0 milestone Sep 3, 2026
@axel-grc

Copy link
Copy Markdown
Collaborator Author

I made some tests, the script does not do a full rebuild each time a cxx files is changed, so ready to be merged I think

@axel-grc
axel-grc requested a review from SimonRit September 11, 2026 10:58

@SimonRit SimonRit left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd change the script to compile ITK with CudaCommon and RTK ON instead of compiling RTK separately. What do you think?

Comment thread utilities/build_rtk_python.sh Outdated
# Prerequisites:
# - An ITK build tree with Python wrapping enabled (set ITK_DIR)
# - Optionally CUDA (set RTK_USE_CUDA=ON).
# When CUDA is enabled, CudaCommon must be findable by ITK.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd remove this line, CudaCommon is in ITK as a remote module so it's always findable. CUDA might not be findable but that's beyond the scope of this script.

Comment on lines +27 to +30
# Verify that ITK Python wrapping is installed in site-packages. RTK wrapping
# builds on top of the ITK wrapping infrastructure, so ITK's wrapping shared
# libraries must already be present.
ITK_PYTHON_DIR=$(python -c "import itk; import os; print(os.path.dirname(itk.__file__))")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If I understand correctly, you must compile ITK first. Why not provide a script that jointly compiles an editable ITK and RTK?

Comment thread INSTALLATION.md Outdated
* Manually download RTK's source repository from [GitHub](https://github.com/RTKConsortium/RTK) with `git` (recommended) or as a [zip package](https://codeload.github.com/RTKConsortium/RTK/zip/main).
* Configure the project with CMake pointing to RTK's source directory and setting the CMake option `ITK_DIR` to ITK's compilation directory. All CMake options above can be set except `Module_RTK`.

A convenience script at `utilities/build_rtk_python.sh` builds and installs RTK as a Python package. It must be run from the RTK source directory. It requires ITK and, when using CUDA, CudaCommon, both built with Python wrapping enabled:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Replace

A convenience script at  `utilities/build_rtk_python.sh`

by

The convenience script [build_rtk_python.sh](utilities/build_rtk_python.sh)

please.

@axel-grc

axel-grc commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator Author

I'd change the script to compile ITK with CudaCommon and RTK ON instead of compiling RTK separately. What do you think?

I'm not sure the joint/editable build is the solution. We can't pip install an ITK source tree, it has no pip build system.
So we can use ITKPythonPackages to build the ITK (and RTK) python packages from a prebuilt ITK. And even then, RTK's hand-written Python (rtkargumentparser.py, init_rtk, rtkExtras, rtkConfig, group/app scripts) has to be copied into the itk python package manually, otherwise the rtk*` applications aren't importable.

@SimonRit

Copy link
Copy Markdown
Collaborator

I'd change the script to compile ITK with CudaCommon and RTK ON instead of compiling RTK separately. What do you think?

I'm not sure the joint/editable build is the solution. We can't pip install an ITK source tree, it has no pip build system. So we can use ITKPythonPackages to build the ITK (and RTK) python packages from a prebuilt ITK. And even then, RTK's hand-written Python (rtkargumentparser.py, init_rtk, rtkExtras, rtkConfig, group/app scripts) has to be copied into the itk python package manually, otherwise the rtk*` applications aren't importable.

Ok, I didn't know one couldn't pip install an ITK source tree. So with this script, one needs to

  • pip install itk (and itk-cudacommon if using CUDA ?)
  • build ITK with Python wrapping
  • build RTK according to the script?

It's currently not clear that one needs to pip install itk first, I would clarify this if this is the proposed procedure.

@axel-grc

Copy link
Copy Markdown
Collaborator Author
  • build RTK ac

We don't need to pip install itk, we just need to build and install itk with python wrapping (and optionally CudaCommon) and give the build path to the script

@SimonRit

Copy link
Copy Markdown
Collaborator
  • build RTK ac

We don't need to pip install itk, we just need to build and install itk with python wrapping (and optionally CudaCommon) and give the build path to the script

I tried to test this (fresh Python env, built ITK, run the script). Here is the result:

(localcomp312) srit@srit-Precision-5480:~/src/rtk/rtk$ ITK_DIR=/home/srit/src/itk/lin64-PythonWrapping-install RTK_PIP_BUILD_DIR=/home/srit/src/rtk/lin64-pip ./utilities/build_rtk_python.sh 
+ RTK_PIP_BUILD_DIR=/home/srit/src/rtk/lin64-pip
+ BUILD_TYPE=Release
+ RTK_USE_CUDA=OFF
+ '[' -z /home/srit/src/itk/lin64-PythonWrapping-install ']'
++ python -c 'import itk; import os; print(os.path.dirname(itk.__file__))'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import itk; import os; print(os.path.dirname(itk.__file__))
    ^^^^^^^^^^
ModuleNotFoundError: No module named 'itk'
+ ITK_PYTHON_DIR=

So pip install itk is required?

Comment thread INSTALLATION.md
* Manually download RTK's source repository from [GitHub](https://github.com/RTKConsortium/RTK) with `git` (recommended) or as a [zip package](https://codeload.github.com/RTKConsortium/RTK/zip/main).
* Configure the project with CMake pointing to RTK's source directory and setting the CMake option `ITK_DIR` to ITK's compilation directory. All CMake options above can be set except `Module_RTK`.

The convenience script [build_rtk_python.sh](utilities/build_rtk_python.sh) builds and installs RTK as a Python package. It must be run from the RTK source directory. It requires ITK and, when using CUDA, CudaCommon, both built with Python wrapping enabled:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

My bad, the link doesn't work. I guess it only works for the .md files copied for readthedocs. Is there a proper way to link to files in the GitHub repository?

@SimonRit

Copy link
Copy Markdown
Collaborator
  • build RTK ac

We don't need to pip install itk, we just need to build and install itk with python wrapping (and optionally CudaCommon) and give the build path to the script

I tried to test this (fresh Python env, built ITK, run the script). Here is the result:

(localcomp312) srit@srit-Precision-5480:~/src/rtk/rtk$ ITK_DIR=/home/srit/src/itk/lin64-PythonWrapping-install RTK_PIP_BUILD_DIR=/home/srit/src/rtk/lin64-pip ./utilities/build_rtk_python.sh 
+ RTK_PIP_BUILD_DIR=/home/srit/src/rtk/lin64-pip
+ BUILD_TYPE=Release
+ RTK_USE_CUDA=OFF
+ '[' -z /home/srit/src/itk/lin64-PythonWrapping-install ']'
++ python -c 'import itk; import os; print(os.path.dirname(itk.__file__))'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import itk; import os; print(os.path.dirname(itk.__file__))
    ^^^^^^^^^^
ModuleNotFoundError: No module named 'itk'
+ ITK_PYTHON_DIR=

So pip install itk is required?

So I progressed by adding the ITK bindings to the PYTHONPATH, as I usually do with my local ITK compilation. Then I had to install scikit_build_core. It's now compiling, I'll let you know if it works...

The error appears when compiling the RTK wrapping independently of ITK
with the script utilities/build_rtk_python.sh:

  In file included from /home/srit/src/itk/lin64-PythonWrapping/Wrapping/castxml_inputs/itkPyBufferRTK.cxx:16:
  /home/srit/src/itk/itk/Modules/Bridge/NumPy/include/itkPyBuffer.h:30:10: fatal error: 'Python.h' file not found
     30 | #include <Python.h>
        |          ^~~~~~~~~~
  1 error generated.
  gmake[2]: *** [Wrapping/Modules/RTK/CMakeFiles/RTKCastXML.dir/build.make:329: /home/srit/src/itk/lin64-PythonWrapping/Wrapping/castxml_inputs/itkPyBufferRTK.xml] Error 1
  gmake[2]: Leaving directory '/home/srit/src/rtk/lin64-toto'
  gmake[1]: *** [CMakeFiles/Makefile2:2357: Wrapping/Modules/RTK/CMakeFiles/RTKCastXML.dir/all] Error 2
  gmake[1]: Leaving directory '/home/srit/src/rtk/lin64-toto'
  gmake: *** [Makefile:146: all] Error 2
@SimonRit

Copy link
Copy Markdown
Collaborator

Ok, it worked with the additional patch I have pushed:
c8c305b
We need to clarify a bit the doc. Should we consider testing the independent compilation of itk-cuda-common?

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