Compatibility errors on Python 3.11 / PyTorch 2.6 / Matplotlib 3.8 (6 issues)
Environment
- Python 3.11
- PyTorch 2.6
- Matplotlib 3.9
- macOS Apple Silicon (MPS)
Fresh install reproduced multiple compatibility issues before inference could run.
Issues encountered
1. psutil missing from requirements.txt
FastSAM imports it through the bundled ultralytics code but it is not installed by default.
2. PyTorch 2.6 checkpoint loading failure
PyTorch 2.6 changed the default behavior of torch.load to weights_only=True, which breaks model loading in:
ultralytics/nn/tasks.pyline 518ultralytics/nn/tasks.pyline 533
Adding weights_only=False restores previous behavior.
3. TkAgg backend crash on macOS
fastsam/prompt.py hardcodes plt.switch_backend("TkAgg") but Tk is not available by default on macOS. Switching to "Agg" works fine since the code only writes images to disk anyway.
4. tostring_rgb() removed in Matplotlib 3.8
Both occurrences in plot_to_result() need to be replaced with buffer_rgba().
5. Wrong channel count after switching to buffer_rgba()
buffer_rgba() returns RGBA (4 channels) but the numpy reshape and cv2 conversion still assumed RGB (3 channels). Updated reshape to (rows, cols, 4) and conversion to COLOR_RGBA2BGR.
6. clip not imported / wrong package installed
fastsam/prompt.py uses clip without importing it at the top of the file. Also openai-clip is not in requirements.txt - the package named clip on PyPI is an unrelated clipboard tool that gets installed instead.
Fixes
All changes are minimal and non-breaking - no API or behavior changes.
I have all fixes tested locally and will submit a PR for this.
Source: CASIA-LMC-Lab/FastSAM