Installation#

Python Version Requirement

PyHealth 2.0 requires Python 3.12 or higher (up to Python 3.13). This is a hard requirement due to dependencies on modern Python features for parallel processing and memory management.

# Verify your Python version
python --version  # Should be 3.12.x or 3.13.x

Recommended Installation (Latest Release)

Install the latest PyHealth 2.0 release from PyPI:

pip install pyhealth

This version includes significant performance improvements, dynamic memory support, parallelized processing, multimodal dataloaders, and many new features.

Legacy Version

The older stable version (1.16) is still available for backward compatibility and supports Python 3.9+:

pip install pyhealth==1.16

Note: The legacy version (1.16) should still work for most use cases, but we recommend using PyHealth 2.0 for better performance and new features.

For Contributors and Developers

If you are contributing to PyHealth or need the latest development features, install from GitHub source:

git clone https://github.com/sunlabuiuc/PyHealth.git
cd PyHealth
pip install -e .

This approach is recommended for developers as it allows you to modify the code and immediately see changes without reinstalling.

Warning 1:

PyHealth has multiple neural network based models, e.g., LSTM, which are implemented in PyTorch. However, PyHealth does NOT install these DL libraries for you. This reduces the risk of interfering with your local copies. If you want to use neural-net based models, please make sure PyTorch is installed. Similarly, models depending on xgboost would NOT enforce xgboost installation by default. Install it with the optional extra:

pip install "pyhealth[xgboost]"

On macOS, XGBoost needs an OpenMP runtime (brew install libomp). PyTorch bundles its own libomp.dylib, and two copies in one process can crash multithreaded XGBoost fits. See pyhealth.models.XGBoostModel for the fix.

CUDA Setting:

To run PyHealth, you may also need CUDA and cudatoolkit that supports your GPU. More info

For example, if you use NVIDIA RTX A6000 as your GPU for training, you should install a compatible cudatoolkit using:

conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch.

Platform-Specific Notes

Windows Subsystem for Linux (WSL)

When using PyHealth on WSL, you may need to disable swap memory due to a bug in how Dask interacts with WSL’s memory management when memory runs out. This prevents performance issues and potential crashes.

Method 1: Using WSL Settings App (Windows 11)

  1. Open the WSL Settings app in Windows

  2. Navigate to Memory and Processor settings

  3. Set Swap size to 0 MB

  4. Apply changes and restart WSL

Method 2: Manual Configuration

  1. Open PowerShell as Administrator

  2. Create or edit %UserProfile%.wslconfig file

  3. Add the following configuration:

[wsl2]
swap=0
  1. Restart WSL by running in PowerShell: wsl --shutdown

macOS: “Too many open files”

PyHealth 2.0.2 and earlier leak a few file descriptors each time a dataset builds its global_event_df cache (the Dask dashboard is never shut down). Processes that build many datasets, such as the unit test suite or a benchmark sweep, can hit macOS’s default limit of 256 open files and fail with OSError: [Errno 24] Too many open files. This is fixed in later versions. On older versions, raise the limit in the shell before running:

ulimit -n 8192

Jupyter notebooks (including VS Code and Cursor)

When a dataset builds its event cache inside a notebook, PyHealth shows a Dask progress bar. With ipywidgets installed it is an interactive widget; without it, PyHealth falls back to a plain text bar. ipywidgets is optional:

pip install ipywidgets

In PyHealth 2.0.0 to 2.1.0, building a dataset in a notebook without ipywidgets failed with ModuleNotFoundError: No module named 'ipywidgets'. Installing ipywidgets works around it on those versions.

Other Platforms

PyHealth should work without additional configuration on:

  • Linux (native)

  • macOS

  • Windows (with proper Python installation)