macOS上にpydicomをセットアップするためのメモ


公式のセットアップ手順 はDebian系のLinux環境を前提としている部分があるため、macOS上でセットアップした際の手順を残しておく

環境情報

  • macOS Catalina 10.15.6
  • Python 3.8.5 on pyenv 1.2.20

※Anacondaは利用しない

セットアップ手順

pydicom

$ pip install pydicom

Optional libraries

$ pip install numpy
$ pip install pillow

CharPyLS

$ pip install cython
$ pip install git+https://github.com/Who8MyLunch/CharPyLS

GDCM

Anacondaなしでは少々手間のかかる部分
Installing the Python GDCM bindings without Conda を参考に、Ubuntu/Debian向けの記述をmacOS向けにアレンジする

$ brew install gdcm

# インストールされた関連ファイルの場所を確認する
$ find /usr -name gdcm.py
/usr/local/lib/python3.8/site-packages/gdcm.py
/usr/local/Cellar/gdcm/3.0.7_1/lib/python3.8/site-packages/gdcm.py

$ find /usr -name "libgdcmCommon.*"
/usr/local/lib/libgdcmCommon.3.0.dylib
/usr/local/lib/libgdcmCommon.3.0.7.dylib
/usr/local/lib/libgdcmCommon.dylib
/usr/local/Cellar/gdcm/3.0.7_1/lib/libgdcmCommon.3.0.dylib
/usr/local/Cellar/gdcm/3.0.7_1/lib/libgdcmCommon.3.0.7.dylib
/usr/local/Cellar/gdcm/3.0.7_1/lib/libgdcmCommon.dylib

# pyenv環境へ関連ファイルをコピー
$ cd ~/.pyenv/versions/3.8.5/lib/python3.8/site-packages/
$ cp /usr/local/lib/python3.8/site-packages/gdcm.py .
$ cp /usr/local/lib/python3.8/site-packages/gdcmswig.py .
$ cp /usr/local/lib/python3.8/site-packages/_gdcmswig* .
$ cp /usr/local/lib/libgd* .

Pythonのプロンプト上で import gdcm してエラーが出なければOK