B Tool Installation
title: B Tool Installation
description: Introduces installation methods for common tools.
B Tool Installation
1. Introduction
Medical imaging algorithm development typically relies on the collaboration of multiple toolchains. This chapter will introduce the core environments required for this tutorial, including Python, ASTRA, BART, MONAI, NiBabel and other basic components. We will start with basic Python environment configuration and gradually explain how to install CT reconstruction library (ASTRA), MRI reconstruction toolbox (BART), deep learning framework (MONAI), and medical imaging file reading/writing tools (NiBabel). Through this section, readers can quickly build a complete, reproducible medical imaging development and reconstruction experimental environment.
2. Direct Python Installation
2.1. Windows System
2.1.1. Download Python Installer
Recommended method: Download the installer from the official Python website
- Open your browser and visit:
https://www.python.org - Click Downloads in the top navigation bar
- The page will automatically recommend the version suitable for Windows, for example: Download Python 3.xx
- Click this button to download a
.exeinstaller (e.g.,python-3.12.3-amd64.exe)
2.1.2. Run the Installer (Most Critical Step)
Double-click the downloaded python-3.xx-amd64.exe and follow these steps:
At the bottom of the installation interface, there is a line:
- ✅ Must check:
Add Python 3.xx to PATH - This step determines whether you can directly use the
pythoncommand in the command line later, which is very important.
- ✅ Must check:
In Customize installation:
Optional Features It is recommended to check all:
- ✅
pip(Python package manager, essential) - ✅
IDLE(built-in small editor for visual debugging of simple scripts) - ✅
Documentation - ✅
Python test suite - ✅
py launcherThen click Next
- ✅
Advanced Options: It is recommended to check:
- ✅
Install for all users(recommended for multi-user computers, path will be inC:\Program Files\Python3x) - ✅
Add Python to environment variables(if you missed checking PATH earlier, you must check it here) - ✅
Precompile standard library(speeds up first run)
- ✅
2.1.3. Verify Python Installation
After installation is complete, follow these steps to check:
Press the
Winkey, typecmd, and open Command PromptIn the black window, type:
bashpython --versionOr
bashpy --versionIf you see something like:
textPython 3.12.3It means the installation was successful and PATH is working.
2.1.4. Verify pip Availability
In the same command line, type:
pip --versionIf you see something like:
pip 24.x from C:\Python\Python312\Lib\site-packages\pip (python 3.12)It means pip has been successfully installed and can be used to install subsequent packages like monai and nibabel.
2.2. Linux System
2.2.1. Check if Python is Already Installed
Open the terminal and type:
python3 --versionIf you see output similar to:
Python 3.10.12It means the system already has Python3, which can generally be used directly.
Then check if pip exists:
pip3 --versionIf it prompts "command not found", it means pip is not installed yet and will be installed later.
2.2.2. Install Python Using Package Manager (Ubuntu / Debian)
2.1 Update Software Sources
First update the package list:
sudo apt update2.2 Install Python3 and Common Dependencies
Execute:
sudo apt install -y python3 python3-pip python3-venvDescription:
python3: Python interpreterpython3-pip: Python package management tool pippython3-venv: Used to create virtual environments (very useful when not installing Conda)
After installation, confirm the versions again:
python3 --version
pip3 --version3. Install Python Using Conda (Recommended)
Conda is the most commonly used environment management tool in the field of data science and medical imaging, capable of creating independent Python environments for different projects to avoid package conflicts.
This section will introduce how to install Conda (Miniconda) on Windows / Linux and create a clean, controllable Python environment.
3.1. Download and Install Miniconda (Recommended)
Why use Miniconda instead of Anaconda?
- Miniconda is more lightweight and doesn't install thousands of unnecessary packages
- More suitable for scientific research projects and medical imaging engineering
- Fully compatible with Anaconda's functionality
3.2. Windows Miniconda Installation
Step 1: Download Installer
Visit the official website:
👉 https://repo.anaconda.com/miniconda/
Select:
- Miniconda3 Windows 64-bit Installer (.exe)
Step 2: Run Installer
Double-click the installer:
Choose Just Me or All Users
Important: Check "Add Miniconda3 to my PATH environment variable"
- If you don't check this, it's okay, Conda will automatically add PATH for CMD / PowerShell
Click Install
Step 3: Verify Installation
Open Anaconda Prompt or CMD:
conda --versionIf it displays:
conda 24.x.xThen the installation is successful.
3. Linux Miniconda Installation
Step 1: Download Installation Script
Visit the official website:
👉 https://docs.conda.io/en/latest/miniconda.html
Copy the Linux installation script link, for example:
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.shStep 2: Run Installation Script
bash Miniconda3-latest-Linux-x86_64.shFollow the prompts:
- Read and agree to the license
- Choose installation path (default is fine:
~/miniconda3) - Choose whether to initialize conda (recommended YES)
Step 3: Activate Conda
If you chose YES earlier, just reopen the terminal.
If you chose NO, you need to manually run:
source ~/miniconda3/bin/activateVerify:
conda --versionStep 4: Create a New Python Environment (Most Critical)
Whether on Windows / Linux, the following steps are completely consistent.
Create a dedicated environment for medical imaging projects, for example medimg:
conda create -n medimg python=3.10Explanation:
-n medimg: Environment namepython=3.10: Specify Python version (most compatible with MONAI/ASTRA/BART)
Activate the environment:
conda activate medimgVerify:
python --versionYou should see:
Python 3.10.x4. Install ASTRA
4.1. ASTRA Toolbox Introduction
ASTRA Toolbox Official Links:
- Official website: https://astra-toolbox.com/
- GitHub repository: https://github.com/astra-toolbox/astra-toolbox
ASTRA Toolbox (All Scale Tomographic Reconstruction Antwerp) is a high-performance computing library specifically designed for X-ray tomography (CT). It provides GPU-accelerated projection and reconstruction algorithms, making it one of the preferred tools for researchers to perform:
- Parallel beam / fan beam / cone beam CT geometric simulation
- Forward projection
- FBP (Filtered Back Projection) fast reconstruction
- Iterative reconstruction algorithms such as ART, SIRT, CGLS
- Deep learning + CT simulation / reconstruction preprocessing
4.2. Windows System ASTRA Toolbox Installation
Install via Conda (Most Recommended)
This is the preferred method for Windows: simple, stable, and no compilation required.
Step 1: Create Python Environment
It is recommended to first create a clean Conda environment (to avoid contaminating the system Python):
conda create -n medimg python=3.10
conda activate medimgPython 3.9–3.11 is recommended (ASTRA official support range).
Step 2: Install ASTRA (CPU Version)
Windows does not support GPU version, so use directly:
conda install -c astra-toolbox astra-toolboxConda will automatically install:
- astra-toolbox (Python interface)
- astra-core (C++ core library)
- Related dependencies (such as numpy, scipy)
Step 3: Verify Installation
Enter Python:
pythonType:
import astra
print(astra.__version__)If the version number (such as 1.10.0) is output normally, the installation is successful.
4.2. Linux System ASTRA Toolbox Installation
Step 1: Create Environment (Strongly Recommended Independent Environment)
conda create -n medimg python=3.10
conda activate medimgStep 2: Install ASTRA (Automatically Select CPU/GPU)
Execute the officially recommended command:
conda install -c astra-toolbox -c nvidia astra-toolboxDescription:
-c astra-toolbox: ASTRA official repository-c nvidia: Used to provide CUDA runtime (required for Linux GPU)- If your system does not have a GPU, the CPU version will be installed
- If you have a GPU, the GPU-accelerated version will be installed (CUDA runtime automatically installed)
No need to manually install CUDA toolkit!
Step 3: Test Installation
python - << 'EOF'
import astra
print("ASTRA version:", astra.__version__)
EOFIf the version number is output, it's successful.
4.3. Test Installation Results
You can use this code to verify if ASTRA is working properly:
import astra
import numpy as np
# 64x64 phantom
vol = np.ones((64, 64), dtype=np.float32)
vol_geom = astra.create_vol_geom(64, 64)
# Parallel beam geometry (180 angles)
angles = np.linspace(0, np.pi, 180, endpoint=False)
proj_geom = astra.create_proj_geom('parallel', 1.0, 64, angles)
pid, sino = astra.create_sino(vol, proj_geom)
print("sino shape:", sino.shape)Expected output:
sino shape: (180, 64)5. Install BART
5.1. BART Introduction
Official website: https://mrirecon.github.io/bart/
GitHub repository: https://github.com/mrirecon/bart
Official documentation: https://bart-doc.readthedocs.io/en/latest/intro.html
Workshop and example material repository: https://github.com/mrirecon/bart-workshop
BART (Berkeley Advanced Reconstruction Toolbox) is an open-source toolbox for MRI (Magnetic Resonance Imaging) reconstruction, signal processing, and rapid prototyping development. It was developed by UC Berkeley and is one of the most widely used reconstruction tools in the medical imaging and MR physics community, especially suitable for researchers.
BART is a high-performance MRI reconstruction and signal processing toolkit characterized by:
Command-line tools + C library + Python/MATLAB interfaces
Supports basic MRI reconstruction:
- FFT / IFFT
- Sense / pSense
- GRAPPA
Supports advanced algorithms:
- CS (Compressed Sensing)
- L1-wavelet / TV regularization
- LLR, LORAKS, low-rank reconstruction
- NUFFT (Non-uniform FFT)
Supports MRI acquisition geometries:
- Multi-coil data
- k-space non-uniform sampling
- Multi-dimensional data (2D/3D/dynamic MRI)
5.2. Windows System BART Installation
Step 1: Environment Preparation
Windows system.
Install a compatible GLC compiler environment (BART has limited official support on Windows). The official provides two paths: use Cygwin or run Linux in a virtual machine.
In the Cygwin environment, you need to install the following packages:
- Devel: gcc, make
- Math: fftw3, fftw3-doc, libfftw3-devel, libfftw3_3
- Math: liblapack-devel, liblapack-doc, liblapack0
If you want GPU acceleration (Windows itself has weak support)—it's generally recommended to do this on Linux. The documentation points out that "Running BART on Windows is not supported" but some users run it through Cygwin/WSL.
Step 2: Download BART Source Code or Release Package
- Open the repository: https://github.com/mrirecon/bart
- Or the official webpage: https://mrirecon.github.io/bart/installation.html → Download the latest version zip/tar package.
- Download the latest Release (such as version 0.9.00) with Windows support instructions.
- Extract the compressed file to a directory, for example C:\tools\bart-0.9.00\
Step 3: Compile and Install Using Cygwin
Install Cygwin: Visit https://www.cygwin.com/, download the installer.
When installing Cygwin, select the corresponding packages in the installation interface (see "Environment Preparation").
Open Cygwin Terminal, in the extracted BART directory, run:
bashcd /cygdrive/c/tools/bart-0.9.00 makeThis will compile BART's command-line tools and libraries.
If you want to support GPU (depends on whether there's an adaptation on Windows, it may fail), you can try adding
CUDA=1in the Makefile, but the official warns that Windows support is limited.
Step 4: Verify Installation on Windows (Cygwin)
In the Cygwin shell, try running a BART tool command:
bashbart fft # If this command outputs help or an error prompt "usage", then installation is successfulWhen calling in Python / MATLAB (if you compiled the Python interface), ensure the library path is in the environment variables.
If you encounter "command not found" or library loading failure, you can check if the environment variable
PATHcontains BART's bin directory, or if Cygwin's usr/bin has been linked.
Tips and Common Issues
- BART support is low in Windows environments, strongly recommend using WSL2 or Linux virtual machines for more stable operation. The documentation explicitly states statements like "Windows support by MSYS2; generic" or "Use Cygwin".
- If just for algorithm reproduction experiments, you can also enable WSL2 on Windows to install Ubuntu, then follow the Linux installation process within WSL2.
- Common errors during compilation: missing
fftw3,lapack,blaslibraries, ensure you select the corresponding dev packages when installing Cygwin. - GPU support is extremely unstable on Windows and not recommended for early research stages.
5.3. Linux System BART Installation
Step 1: Environment Preparation
Recommended dependencies to install first:
sudo apt-get update
sudo apt-get install -y \
gcc \
make \
libfftw3-dev \
liblapacke-dev \
libpng-dev \
libopenblas-devgcc,make: Compilation tools.libfftw3-dev: FFTW (Fast Fourier Transform Library) development package.liblapacke-dev: LAPACK/BLAS related development package.libpng-dev: If you need image reading/writing support.libopenblas-dev: Recommended to accelerate BLAS operations.
Step 2: Download BART Source Code or Release Package
Download the latest version from the official page or GitHub repository:
git clone https://github.com/mrirecon/bart.git
cd bartOr download .tar.gz from the release page:
wget https://github.com/mrirecon/bart/archive/v0.9.00.tar.gz
tar xzvf v0.9.00.tar.gz
cd bart-0.9.00Step 3: Compile Install, Enable GPU Acceleration (Optional)
In the source code directory, run:
makeIf you want to enable additional features (such as ISMRMRD support):
make ismrmrdIf your machine has an NVIDIA graphics card and you want to use GPU acceleration, BART supports CUDA.
Execute in the source code directory during compilation:
make clean
make CUDA=1This enables GPU support. You need to install the corresponding CUDA version, NVIDIA driver, CUDA Toolkit, etc.
Step 4: Install Python Interface (Optional)
If you plan to use BART in Python, many versions have a built-in python/ directory in the source code. It is recommended:
cd python
pip install .Then test in Python:
import bart
bart.print_settings()Step 5: Verify Installation is Successful
Execute in the terminal:
bart fft # Display help informationYou can also run a simple command-line reconstruction tool to test. If it can output the version number, help information, or no errors, it indicates successful installation.
6. Install MONAI
6.1. MONAI Introduction
- Official website: https://monai.dev/
- GitHub repository: https://github.com/Project-MONAI/MONAI
- Official documentation: https://docs.monai.io/ (including installation guide, API documentation, etc.)
MONAI (Medical Open Network for AI) is a medical imaging deep learning framework jointly led by NVIDIA + US NIH (National Institutes of Health).
It is based on PyTorch and specifically designed for medical imaging tasks (CT / MRI / X-ray / Ultrasound), providing a complete toolchain from data loading, preprocessing, training, evaluation to deployment.
MONAI has become one of the most mainstream open-source frameworks in medical imaging AI research.
6.2. Pre-Installation Preparation
Before installing MONAI, you need to:
- Install Miniconda or Anaconda
- Install Python 3.9–3.11 (3.10 recommended)
- Optional: Install NVIDIA drivers (if GPU is needed)
- It is recommended to use an independent conda environment
6.3. Install PyTorch
MONAI depends on PyTorch, so PyTorch must be installed first.
Go to the PyTorch official installation page:
Select the corresponding system's command.
● CPU Version (Windows / Linux Universal)
pip install torch torchvision torchaudio● GPU Version (using CUDA 12.4 as an example)
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124If you don't know the CUDA version, run
nvidia-smi(Linux) or check the NVIDIA Control Panel (Windows).
6.4. Install MONAI
pip install monaiInstall Optional Extension Dependencies (Optional)
Common enhancement packages:
pip install "monai[nibabel,skimage,pillow,ignite]"All optional dependencies (most complete version):
pip install "monai[all]"Suitable for research tasks (such as segmentation / registration).
6.5. Installation Verification
Run the following Python script:
import monai
import torch
print("MONAI version:", monai.__version__)
print("PyTorch version:", torch.__version__)
print("CUDA available:", torch.cuda.is_available())If there are no errors and the existing versions are output, it means the installation is successful.
7. Install NiBabel
7.1. NiBabel Introduction
- GitHub repository (source code + issues + developers): https://github.com/nipy/nibabel
- Official documentation: https://nipy.org/nibabel/
- PyPI: https://pypi.org/project/nibabel/
NiBabel is a Python toolkit specifically designed for reading, processing, and saving medical imaging files, supporting mainstream formats such as NIfTI (.nii/.nii.gz), Analyze, MINC, MGH/MGZ, etc. It can load medical imaging data as NumPy arrays while providing complete metadata management such as affine matrices, spatial orientations, and header information. It is one of the most commonly used file I/O libraries in medical imaging AI, neuroimaging (fMRI/dMRI), deep learning preprocessing, and scientific analysis, and is also one of the underlying basic components of MONAI, PyTorch, and various medical imaging toolchains.
7.2. Install Current Stable Version (Recommended)
Use pip to install the latest released version of NiBabel:
pip install nibabel7.3. Install Latest Development Version
If you want to use the latest development progress on GitHub (unreleased version), you can run:
pip install git+https://github.com/nipy/nibabel7.4. Install in "Editable Mode" (Used when Developing NiBabel Source Code)
When you need to modify NiBabel source code, participate in development, or debug, you can install in editable mode:
git clone https://github.com/nipy/nibabel.git
pip install -e ./nibabelThis method makes Python directly reference the local source code directory, so no reinstallation is needed after modifications.
7.5. Test NiBabel
1. Run Complete Tests During Development (Recommended for Developers Using tox)
git clone https://github.com/nipy/nibabel.git
cd nibabel
toxtox will automatically create virtual environments and test NiBabel under multiple Python versions, suitable for users participating in development.
2. Test Installed NiBabel
If you just want to test the NiBabel installed in your current system, you can install test dependencies and run pytest:
pip install nibabel[test]
pytest --pyargs nibabelThis will run all test modules of NiBabel to ensure the installation is normal.