etc

# 맥 matplotlib error 해결방법

Tigercow.Door 2018. 4. 10. 14:17


# 맥에서 matplotlib 오류 해결방안


RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.


맥에서 matplotlib 을 사용하려는 분들 중 위와 같은 오류가 발생하는 분들이 있을 것입니다.

이는 matplotlib 에서 사용되는 backend 를 알맞게 설정하지 못한 이유 때문에 발생하는 오류입니다.

이를 해결하는 방법으로는 matplotlib 의 자체적인 스크립트를 수정하는 방법 또는 매 프로젝트 마다 명시적으로 backend 를 설정하는 방법이 있습니다.

아무래도 첫번째 방법이 한번만 설정해두면 되기 때문에 간편한 점이 있습니다.



1. matplotlib 스크립트 수정하기


맥에서 터미널을 열어서 아래와 같은 명령어를 입력합니다.


echo "backend: TkAgg" >> ~/.matplotlib/matplotlibrc


아무말이 안떠야 정상입니다 :)

이후 matplotlib 을 사용해보면 정상적으로 되는 것을 확인할 수 있습니다.




2. 프로젝트에서 자체적으로 명시해주기


이는 프로젝트에서


import matplotlib


을 한 이후에 아래와 같은 코드를 작성해줍니다.


matplotlib.use('TkAgg')




이렇게 맥에서 matplotlib error에 대한 해결방법을 알아보았습니다.

728x90