반응형

 

IPython을 사용하다보면 %matplotlib inline을 사용 해야 하는 상황이 발생합니다.

도형이나 그래프로 output을 출력 하는 라이브러리 이므로 Qtconsole 환경이 필요합니다.

 

그럴 때, IPython qtconsole을 실행 하면 다음과 같은 에러가 발생할 수도 있습니다.

이럴 경우 에러 코드의 마지막을 보면 다음과 같이 필요한 라이브러리가 있습니다.

해당 라이브러리를 설치해주시면 문제 없이 실행 됩니다.

 

 

[에러코드]

 

[TerminalIPythonApp] WARNING | Subcommand `ipython qtconsole` is deprecated and will be removed in future versions.
[TerminalIPythonApp] WARNING | You likely want to use `jupyter qtconsole` in the  future
Error in sys.excepthook:
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\qtconsole\qtconsoleapp.py", line 49, in gui_excepthook
    old_excepthook(exctype, value, tb)
TypeError: 'NoneType' object is not callable
 .........................

    Could not load requested Qt binding. Please ensure that
    PyQt4 >= 4.7, PyQt5 or PySide >= 1.0.3 is available,
    and only one is imported per session.

    Currently-imported Qt library:   None
    PyQt4 installed:                 False
    PyQt5 installed:                 False
    PySide >= 1.0.3 installed:       False
    Tried to load:                   ['pyqt5', 'pyside', 'pyqt']

 

pip install PySide

pip install PyQt4

pip install PyQt5

 

필자의 경우는 PySide만 설치가 가능했으며, PySide를 설치한 이후 문제 없이 qtconsole이 실행 되었습니다.

 

 

Jupyter QtConsole 4.2.1
Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 4.2.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
 

In [1]:

 

그래픽 라이브러리를 사용하기 위해서는 console에서 동작하기엔 옵션이 필요하다.

그럴땐 notebook을 활용해야 한다.

 

ipython notebook

 

E:\Temp\Data_Science\IPython\chapter\02>ipython notebook
[TerminalIPythonApp] WARNING | Subcommand `ipython notebook` is deprecated and will be removed in future versions.
[TerminalIPythonApp] WARNING | You likely want to use `jupyter notebook` in the future
C:\Python27\lib\site-packages\widgetsnbextension\__init__.py:30: UserWarning: To use the jupyter-js-widgets nbextension, you'll need to update the Jupyter notebook to version 4.2 or later.
  the Jupyter notebook to version 4.2 or later.""")
[I 10:15:53.674 NotebookApp] Serving notebooks from local directory: E:\Temp\Data_Science\IPython\chapter\02
[I 10:15:53.674 NotebookApp] 0 active kernels
[I 10:15:53.674 NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/
[I 10:15:53.674 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). 

 





Plot을 사용하는데 다음과 같은 오류가 발생할 경우 32bit 환경에서 사용하였기 때문입니다.

따라서, 64bit로 다시 진행 해 보세요.

 

 

total_births.plot(title='Total births by sex and year') 

error >

c:\python27\lib\lib-tk\Tkinter.py in <module>()
     36 if sys.platform == "win32":
     37     # Attempt to configure Tcl/Tk without requiring PATH
---> 38     import FixTk
     39 import _tkinter # If this fails your Python may not be configured for Tk
     40 tkinter = _tkinter # b/w compat for export

c:\python27\lib\lib-tk\FixTk.py in <module>()
     63     # Compute TK_LIBRARY, knowing that it has the same version
     64     # as Tcl
---> 65     import _tkinter
     66     ver = str(_tkinter.TCL_VERSION)
     67     if "TK_LIBRARY" not in os.environ:

ImportError: DLL load failed: %1은(는) 올바른 Win32 응용 프로그램이 아닙니다.

 

추가적으로 plot이 정상적으로 동작하지 않을 경우 다음과 같이 진행 하면 그래프가 출력 됩니다.

 

 

total_births.plot(title='total births by sex and year')

 

error>

<matplotlib.axes._subplots.AxesSubplot at 0xf05df60>
[이후 아무것도 출력 되지 않음]

 

[해결책]

 

%matplotlib inline 

<matplotlib.axes._subplots.AxesSubplot at 0xf05df60>

[이후 정상적으로 출력 됨.]

 



반응형

+ Recent posts