[python] 'ValueError: <COMPRESSION.LZW: 5> requires the 'imagecodecs' package' 오류 해결 방법

개요

python에서 'ValueError: <COMPRESSION.LZW: 5> requires the 'imagecodecs' package' 오류가 발생함

ValueError

펭귄은 python의 tifffile 패키지를 사용해서, 이미지를 처리하다가 위 에러가 발생했다.

 

Error

Python에서 TIFF 파일을 처리할 때 ValueError: <COMPRESSION.LZW: 5> requires the 'imagecodecs' package 오류가 발생할 수 있다. 이 오류는 imagecodecs 패키지가 설치되지 않았거나, 호환되지 않는 버전이 설치되었을 때 발생한다.

ValueError: <COMPRESSION.LZW: 5> requires the 'imagecodecs' package

 

주요 원인

  • imagecodecs 패키지가 설치되지 않음
  • imagecodecs의 버전이 맞지 않음
  • tifffile 또는 Pillow 버전이 너무 오래되었거나, 호환되지 않는 경우

해결 방법

오류 해결을 위해 아래의 방법들을 확인해 보면 된다. 펭귄은 imagecodes를 설치해서 해결했다.

  • imagecodes 패키지 설치
  • tifffile 패키지 업데이트
  • conda install 사용
  • 패키지 호환성 확인

imagecodes 패키지 설치

imagecodecs가 설치되지 않았을 경우, 다음 명령어로 설치할 수 있다.

pip install imagecodecs

 

펭귄은 imagecodecs가 설치되어 있지 않아서, 아래와 같이 설치됐다.

imagecodes 설치

 

최신 버전을 설치하려면 다음 명령어를 실행한다.

pip install --upgrade imagecodecs

tifffile  패키지 업데이트

imagecodecs가 이미 설치되어 있음에도 오류가 발생한다면, 관련 패키지를 최신 버전으로 업데이트해 본다.

pip install --upgrade tifffile Pillow

conda 환경을 사용하는 경우

Anaconda 또는 Miniconda 환경을 사용한다면 다음 명령어로 imagecodecs를 설치한다.

conda install -c conda-forge imagecodecs

패키지 충돌 확인

pip list 명령어를 실행하여 imagecodecs, tifffile, Pillow의 버전을 확인한다.

pip list | grep -E 'imagecodecs|tifffile|Pillow'

펭귄은 Pillow는 설치하지 않아서, 아래 두 개 패키지만 확인 됐다.

pip list

필요한 경우 특정 버전으로 재설치할 수도 있다. 이때, 각 패키지 호환 버전을 확인해야 한다.

# 예시
pip install imagecodecs==2023.1.23
pip install tifffile==2023.3.21
pip install Pillow==9.4.0