1. scikit-image のインストール#

1.1. サポートされているプラットフォーム#

  • x86 プロセッサ搭載の Windows 64 ビット

  • x86 および ARM (M1 など) プロセッサ搭載の macOS

  • x86 および ARM プロセッサ搭載の Linux 64 ビット

公式には他のプラットフォームはサポートしていませんが、ソースからビルドを試すことができます。

1.2. バージョン確認#

scikit-image が既にインストールされているか、インストールが成功したかどうかを確認するには、Python シェルまたは Jupyter Notebook で次のコマンドを実行します。

import skimage as ski
print(ski.__version__)

または、コマンドラインから

python -c "import skimage; print(skimage.__version__)"

(python が失敗した場合は、python3 を試してください。)

scikit-image がインストールされていればバージョン番号が表示され、インストールされていない場合はエラーメッセージが表示されます。

1.3. pip と conda を使用したインストール#

1.3.1. pip#

pip インストールの前提条件:コマンドラインでパッケージをインストールするために pip を使用できる必要があります。

仮想環境の使用を強くお勧めします。仮想環境は、既存のシステムインストールに干渉せず、簡単に削除でき、アプリケーションに必要なパッケージバージョンのみを含む、クリーンな Python 環境を作成します。

最新の scikit-image をインストールするには、Python 3.10 以上が必要です。Python のバージョンが古い場合は、pip によって最も新しい互換バージョンが検出されます。

# Update pip
python -m pip install -U pip

# Install scikit-image
python -m pip install -U scikit-image

skimage.data のすべてのサンプルデータセットにアクセスするには、いくつかの追加の依存関係が必要です。それらは次のようにインストールします。

python -m pip install -U scikit-image[data]

例: 並列処理を含む scikit-image の機能を拡張するオプションの科学的 Python パッケージをインストールするには、次を使用します。

python -m pip install -U scikit-image[optional]

警告

sudopip を一緒に使用しないでください。 pip によって重要なシステムライブラリが上書きされる可能性があります。

1.3.2. conda#

miniforge をお勧めします。これは、ライセンス費用なしで conda-forge を使用する最小限のディストリビューションです。Python をインストールし、仮想環境を提供します。

conda 環境を設定したら、次のようにして scikit-image をインストールします。

conda install scikit-image

1.4. システムパッケージマネージャ#

パッケージマネージャ (aptdnf など) を使用して scikit-image またはその他の Python パッケージをインストールすることは、古いバージョンを取得する可能性が高いため、最良の方法ではありません。また、パッケージマネージャによって提供されていない他の Python パッケージのインストールも難しくなります。

1.5. すべてのデモデータセットのダウンロード#

いくつかのサンプル画像 (skimage.data 内) はオンラインでホストされており、デフォルトではインストールされません。これらの画像は、最初にアクセスしたときにダウンロードされます。すべてのデモデータセットをオフラインでアクセスできるようにダウンロードする場合は、pooch がインストールされていることを確認してから、次のコマンドを実行します。

python -c 'import skimage as ski; ski.data.download_all()'

1.6. 追加のヘルプ#

ご不明な点がございましたら、

をご利用ください。これらの手順を変更したい場合は、GitHub で issue を作成してください

2. コントリビュータのための scikit-image のインストール#

システムには次のものがインストールされている必要があります。

  • C コンパイラ、

  • C++ コンパイラ、および

  • scikit-image でサポートされている Python のバージョン (pyproject.toml を参照)。

まず、GitHub 上で scikit-image リポジトリをフォークします。次に、フォークをローカルにクローンし、元の scikit-image リポジトリを指す upstream リモートを設定します。

注記

以下では git@github.com を使用しています。SSH キーが設定されていない場合は、代わりに https://github.com を使用してください。

git clone git@github.com:YOURUSERNAME/scikit-image
cd scikit-image
git remote add upstream git@github.com:scikit-image/scikit-image

以下のすべてのコマンドは、クローンされた scikit-image ディレクトリ内から実行されます。

2.1. ビルド環境の設定#

scikit-image に合わせた Python 開発環境を設定します。ここでは、2 つの一般的な環境マネージャである venv (pip) と conda (miniforge) の手順を示します。

2.1.1. venv#

# Create a virtualenv named ``skimage-dev`` that lives outside of the repository.
# One common convention is to place it inside an ``envs`` directory under your home directory:
mkdir ~/envs
python -m venv ~/envs/skimage-dev

# Activate it
# (On Windows, use ``skimage-dev\Scripts\activate``)
source ~/envs/skimage-dev/bin/activate

# Install development dependencies
pip install -r requirements.txt
pip install -r requirements/build.txt

# Install scikit-image in editable mode. In editable mode,
# scikit-image will be recompiled, as necessary, on import.
spin install -v

ヒント

上記のコマンドは、scikit-image を環境にインストールします。これにより、IDE、IPython などからアクセスできるようになります。これは厳密には必須ではありません。次のようにビルドすることもできます。

spin build

その場合、ライブラリはインストールされませんが、spin コマンド(例:spin testspin ipythonspin run など)を使用してアクセスできます。

2.1.2. conda#

ライセンス費用なしで Anaconda の代替となる miniforge を使用して conda をインストールすることをお勧めします。

miniforge をインストールした後

# Create a conda environment named ``skimage-dev``
conda create --name skimage-dev

# Activate it
conda activate skimage-dev

# Install development dependencies
conda install -c conda-forge --file requirements/default.txt
conda install -c conda-forge --file requirements/test.txt
conda install -c conda-forge pre-commit ipython
conda install -c conda-forge --file requirements/build.txt

# Install scikit-image in editable mode. In editable mode,
# scikit-image will be recompiled, as necessary, on import.
spin install -v

ヒント

上記のコマンドは、scikit-image を環境にインストールします。これにより、IDE、IPython などからアクセスできるようになります。これは厳密には必須ではありません。次のようにビルドすることもできます。

spin build

その場合、ライブラリはインストールされませんが、spin コマンド(例:spin testspin ipythonspin run など)を使用してアクセスできます。

2.2. テスト#

完全なテストスイートを実行します。

spin test

または、テストの一部を実行します。

# Run tests in a given file
spin test skimage/morphology/tests/test_gray.py

# Run tests in a given directory
spin test skimage/morphology

# Run tests matching a given expression
spin test -- -k local_maxima

2.3. フィーチャブランチの追加#

新しい機能を貢献する際には、フィーチャブランチを使用してください。

まず、最新のソースを取得します。

git switch main
git pull upstream main

フィーチャブランチを作成します。

git switch --create my-feature-name

編集可能なインストールを使用すると、scikit-image は必要に応じて自動的に再構築されます。手動でビルドする場合は、次のように再構築します。

.. code-block:: sh

spin build

繰り返し行われる増分ビルドは通常問題ありませんが、ビルドの問題が発生した場合は、次のように最初から再構築してください。

spin build --clean

2.4. プラットフォーム固有の注意事項#

Windows

Windows での scikit-image のビルドは、継続的インテグレーションテストの一部として実行されます。手順は、このAzure Pipelineに示されています。

Debian と Ubuntu

ライブラリのコンパイル前に、適切なコンパイラをインストールします。

sudo apt-get install build-essential

2.5. 完全な要件リスト#

ビルド要件

# Generated via tools/generate_requirements.py and pre-commit hook.
# Do not edit this file; modify pyproject.toml instead.
meson-python>=0.16
setuptools>=68
ninja>=1.11.1.1
Cython>=3.0.8
pythran>=0.16
numpy>=2.0
spin==0.13
build>=1.2.1

実行時要件

# Generated via tools/generate_requirements.py and pre-commit hook.
# Do not edit this file; modify pyproject.toml instead.
numpy>=1.24
scipy>=1.11.2
networkx>=3.0
pillow>=10.1
imageio>=2.33,!=2.35.0
tifffile>=2022.8.12
packaging>=21
lazy-loader>=0.4

テスト要件

# Generated via tools/generate_requirements.py and pre-commit hook.
# Do not edit this file; modify pyproject.toml instead.
asv
numpydoc>=1.7
pooch>=1.6.0
pytest>=7.0
pytest-cov>=2.11.0
pytest-localserver
pytest-faulthandler
pytest-doctestplus

ドキュメント要件

# Generated via tools/generate_requirements.py and pre-commit hook.
# Do not edit this file; modify pyproject.toml instead.
sphinx>=8.0
sphinx-gallery[parallel]>=0.18
numpydoc>=1.7
sphinx-copybutton
matplotlib>=3.7
dask[array]>=2022.9.2
pandas>=2.0
seaborn>=0.11
pooch>=1.6
tifffile>=2022.8.12
myst-parser
intersphinx-registry>=0.2411.14
ipywidgets
ipykernel
plotly>=5.20
kaleido==0.2.1
scikit-learn>=1.2
sphinx_design>=0.5
pydata-sphinx-theme>=0.16
PyWavelets>=1.6
pytest-doctestplus

開発者要件

# Generated via tools/generate_requirements.py and pre-commit hook.
# Do not edit this file; modify pyproject.toml instead.
pre-commit
ipython
tomli; python_version < '3.11'

データ要件

デモデータセットの完全なセットは、次のものがインストールされている場合のみ利用可能です。

# Generated via tools/generate_requirements.py and pre-commit hook.
# Do not edit this file; modify pyproject.toml instead.
pooch>=1.6.0

オプション要件

上記の必須要件で scikit-image を使用できますが、一部の機能は次のものがインストールされている場合のみ利用できます。

  • Matplotlib 様々な関数で使用されます(例:描画、セグメンテーション、画像の読み込み)。

  • Dask dask モジュールは、特定の関数の並列化に使用されます。

まれに、次のものも必要になる場合があります。

  • PyAMG pyamg モジュールは、ランダムウォーカーセグメンテーションの高速 cg_mg モードに使用されます。

  • Astropy FITS I/O 機能を提供します。

  • SimpleITK 幅広いフォーマット(生医学画像で使用される特殊なフォーマットを含む)を提供するオプションの I/O プラグインです。

# Generated via tools/generate_requirements.py and pre-commit hook.
# Do not edit this file; modify pyproject.toml instead.
SimpleITK
astropy>=5.0
cloudpickle>=0.2.1
dask[array]>=2021.1.0,!=2024.8.0
matplotlib>=3.7
pooch>=1.6.0
pyamg>=5.2
PyWavelets>=1.6
scikit-learn>=1.2

2.6. コントリビュータのインストールに関するヘルプ#

上記追加のヘルプを参照してください。