Skip to content

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

Merged
SimonRit merged 1 commit into
RTKConsortium:mainfrom
axel-grc:PythonInstall
Nov 2, 2026
Merged

SimonRit merged 1 commit into
RTKConsortium:mainfrom
axel-grc:PythonInstall

Conversation

@axel-grc

@axel-grc axel-grc commented Jul 31, 2026 •

Copy link
Copy Markdown
Collaborator

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge, with the existing non-blocking issue for interpreter paths containing spaces.

Findings

  1. P2 Spaces prevent commands from starting ▶

Summary

Adds a script to build and install RTK's Python files beside an existing ITK package.

  • The installer builds RTK's Python wrapping into an ITK package folder.
  • The selected Python environment can import RTK and run its apps.

SimonRit dismissed the earlier Python 3.8 concern because ITK no longer supports it; Greptile withdrew that finding.

Reviews (7) · Last reviewed commit: "ENH: Add RTK Python package install scri..." · Reviewed by Greptile

@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 Resolved
Comment thread utilities/build_rtk_python.sh Resolved
@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 thread utilities/build_rtk_python.sh Outdated
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 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`.

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...

@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?

@axel-grc
axel-grc force-pushed the PythonInstall branch 4 times, most recently from 2ea758a to 0d78831 Compare September 29, 2026 13:23
@axel-grc
axel-grc force-pushed the PythonInstall branch 2 times, most recently from a9f9f82 to cd15636 Compare October 7, 2026 14:03
@axel-grc

axel-grc commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator Author

I confirmed that the editable mod of pip does not work, so there is no reason to use pip install, we can install rtk with cmake and create symlinks in the script like I did.
This way, the bindings can be used across all environments just by adding it to pythonpath or using a .pth

Comment thread INSTALLATION.md Resolved
@axel-grc
axel-grc requested a review from SimonRit October 28, 2026 09:07
@SimonRit
SimonRit force-pushed the PythonInstall branch 2 times, most recently from c4bb53d to 242d3d6 Compare November 2, 2026 07:36
[ -f "$src" ] || continue
name=$(basename "$src" .py)
cat > "$SCRIPTS_DIR/$name" <<EOF
#!$PYTHON_BIN

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Spaces prevent commands from starting

If the selected Python environment lives in a directory containing spaces, #!$PYTHON_BIN produces an invalid interpreter line on Linux. The generated commands fail before importing the application, even though installation succeeds. Generate a shell launcher that quotes the interpreter path, as Python package installers do.

@SimonRit
SimonRit merged commit 0c569ef into RTKConsortium:main Nov 2, 2026
13 of 17 checks passed
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