본문 바로가기

맥(솔라리스)

macOS에서 Python ModuleNotFoundError: No module named 'PIL' 해결하는 방법

반응형

macOS에서 Python ModuleNotFoundError: No module named 'PIL' 해결하는 방법

테스트 환경

$ sw_vers
ProductName:	macOS
ProductVersion:	12.5
BuildVersion:	21G72
$ python --version
Python 3.9.13

Module Not Found Error

macOS 환경에서 Python 스크립트를 실행할 때 아래와 같은 오류가 발생하는 경우가 있습니다.

Traceback (most recent call last):
  File "/Users/.../convert_image.py", line 2, in <module>
    from PIL import Image
ModuleNotFoundError: No module named 'PIL'

이 오류는 이미지 처리 라이브러리 Pillow(PIL) 가 설치되어 있지 않거나 현재 실행 중인 Python 환경과 다른 위치에 설치된 경우 발생합니다.

pillow(PIL) 모듈 설치

pip 명령을 사용하여 pillow(PIL) 모듈 설치

pip3 install Pillow
$ pip3 install Pillow
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
Collecting Pillow
  Downloading Pillow-9.2.0-cp39-cp39-macosx_11_0_arm64.whl (2.8 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.8/2.8 MB 29.9 MB/s eta 0:00:00
Installing collected packages: Pillow
  DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
Successfully installed Pillow-9.2.0

설치 확인

$ pip3 list | egrep -i pillow
Pillow             9.2.0

정상 동작 테스트

  • 모듈이 정상 인식되는지 확인합니다.
python3 -c "from PIL import Image; print('Pillow OK')"
Pillow OK

 

728x90
반응형