IPython 에서 matplotlib import 시 cannot import name 'QtCore' 오류 발생 처리


Think Stats 2 PDF 를 보다가 첫 SOURCE 코드를 테스트 시 오류가 발생하였다.

확인해 보니 IPython에서 matplotlib 를 import 시 cannot import name 'QtCore' 오류 발생 처리


내 PC의 Python 버전은 3.4이다. , matplotlib 를 import 시 QtCore 5와 QtCore 4 간에 불일치로 문제가 발생되는 것 같다.

아래와 같이 matplotlib.use("Qt5Agg") 를 IPython에서 수행하여 해결하였다. 이 때 주의할 사항이 있는데 오류가 난 Ipython 콘솔에서 해당 설정을 수행하면 Warning 메시지가 나오면서 이미 Backend가 설정되어 해당 설정은 적용되지 않는다는 것이다. 반드시 새로운 콘솔창을 열고 해당 명령어를 입력하자.


import matplotlib


matplotlib.use("Qt5Agg")


C:\Anaconda3\lib\site-packages\matplotlib\__init__.py:1350: UserWarning:  This call to matplotlib.use() has no effect
because the backend has already been chosen;
matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time.

반드시 새로운 콘솔창을 열고 해당 메시지를 입력하자.



+ Recent posts