2016-11-21 1 views
0

다음 Python 코드에서 오류가 발생합니다. 나는 대본에서 달리고있다. 파이썬 2.7.12를 사용하여 메신저.Python 스크립트 실행 중 오류가 발생했습니다. AttributeError : 'NoneType'객체에 'run_line_magic'속성이 없습니다.

import os 
import numpy as np 
import pandas as pd 
import matplotlib.pyplot as plt 
from IPython import get_ipython 
ipython_shell = get_ipython() 
get_ipython().run_line_magic('matplotlib', 'inline') 

나는 py와 jpy 확장을 모두 사용해 보았습니다. matplotlib 가져 오기 구문을 변경하려고했지만 아무 것도 작동하지 않습니다.이

사용하여 스크립트를 실행하려고 ipykernel 설치 한 후 ipython이 제공 :

파이썬 실행에서 오류가 iPython와 함께 실행

Traceback (most recent call last): 
    File "LR.jpy", line 7, in <module> 
    get_ipython().run_line_magic('matplotlib', 'inline') 
AttributeError: 'NoneType' object has no attribute 'run_line_magic' 

오류를 보여준다는

--------------------------------------------------------------------------- 
ImportError        Traceback (most recent call last) 
C:\Users\Roland\Google Drive\Work\Machine Learning\machine-learning-ex1\ex1\LR.jpy in <module>() 
     5 from IPython import get_ipython 
     6 ipython_shell = get_ipython() 
----> 7 get_ipython().run_line_magic('matplotlib', 'inline') 

c:\program files\python\lib\site-packages\IPython\core\interactiveshell.pyc in run_line_magic(self, magic_name, line) 
    2077     kwargs['local_ns'] = sys._getframe(stack_depth).f_locals 
    2078    with self.builtin_trap: 
-> 2079     result = fn(*args,**kwargs) 
    2080    return result 
    2081 

<decorator-gen-105> in matplotlib(self, line) 

c:\program files\python\lib\site-packages\IPython\core\magic.pyc in <lambda>(f, *a, **k) 
    186  # but it's overkill for just that one bit of state. 
    187  def magic_deco(arg): 
--> 188   call = lambda f, *a, **k: f(*a, **k) 
    189 
    190   if callable(arg): 

c:\program files\python\lib\site-packages\IPython\core\magics\pylab.pyc in matplotlib(self, line) 
    98    print("Available matplotlib backends: %s" % backends_list) 
    99   else: 
--> 100    gui, backend = self.shell.enable_matplotlib(args.gui) 
    101    self._show_matplotlib_backend(args.gui, backend) 
    102 

c:\program files\python\lib\site-packages\IPython\core\interactiveshell.pyc in enable_matplotlib(self, gui) 
    2945     gui, backend = pt.find_gui_and_backend(self.pylab_gui_select) 
    2946 
-> 2947   pt.activate_matplotlib(backend) 
    2948   pt.configure_inline_support(self, backend) 
    2949 

c:\program files\python\lib\site-packages\IPython\core\pylabtools.pyc in activate_matplotlib(backend) 
    293 
    294  import matplotlib.pyplot 
--> 295  matplotlib.pyplot.switch_backend(backend) 
    296 
    297  # This must be imported last in the matplotlib series, after 

c:\program files\python\lib\site-packages\matplotlib\pyplot.pyc in switch_backend(newbackend) 
    230  matplotlib.use(newbackend, warn=False, force=True) 
    231  from matplotlib.backends import pylab_setup 
--> 232  _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup() 
    233 
    234 

c:\program files\python\lib\site-packages\matplotlib\backends\__init__.pyc in pylab_setup() 
    30  # imports. 0 means only perform absolute imports. 
    31  backend_mod = __import__(backend_name, 
---> 32        globals(),locals(),[backend_name],0) 
    33 
    34  # Things we pull in from all backends 

ImportError: No module named ipykernel.pylab.backend_inline 

EDIT 보여줍니다 나 followng errors

두 번째 경우 IPython

Help on function get_ipython in module IPython.core.getipython: 

get_ipython() 
    Get the global InteractiveShell instance. 

    Returns None if no InteractiveShell instance is registered. 

를 실행하는 경우 첫 번째 경우에

--------------------------------------------------------------------------- 
UnknownBackend       Traceback (most recent call last) 
C:\Users\Roland\Google Drive\Work\Machine Learning\machine-learning-ex1\ex1\LR.py in <module>() 
     5 from IPython import get_ipython 
     6 ipython_shell = get_ipython() 
----> 7 get_ipython().run_line_magic('matplotlib', 'inline') 

c:\program files\python\lib\site-packages\IPython\core\interactiveshell.pyc in run_line_magic(self, magic_name, line) 
    2077     kwargs['local_ns'] = sys._getframe(stack_depth).f_locals 
    2078    with self.builtin_trap: 
-> 2079     result = fn(*args,**kwargs) 
    2080    return result 
    2081 

<decorator-gen-105> in matplotlib(self, line) 

c:\program files\python\lib\site-packages\IPython\core\magic.pyc in <lambda>(f, *a, **k) 
    186  # but it's overkill for just that one bit of state. 
    187  def magic_deco(arg): 
--> 188   call = lambda f, *a, **k: f(*a, **k) 
    189 
    190   if callable(arg): 

c:\program files\python\lib\site-packages\IPython\core\magics\pylab.pyc in matplotlib(self, line) 
    98    print("Available matplotlib backends: %s" % backends_list) 
    99   else: 
--> 100    gui, backend = self.shell.enable_matplotlib(args.gui) 
    101    self._show_matplotlib_backend(args.gui, backend) 
    102 

c:\program files\python\lib\site-packages\IPython\core\interactiveshell.pyc in enable_matplotlib(self, gui) 
    2950   # Now we must activate the gui pylab wants to use, and fix %run to take 
    2951   # plot updates into account 
-> 2952   self.enable_gui(gui) 
    2953   self.magics_manager.registry['ExecutionMagics'].default_runner = \ 
    2954    pt.mpl_runner(self.safe_execfile) 

c:\program files\python\lib\site-packages\IPython\terminal\interactiveshell.pyc in enable_gui(self, gui) 
    450  def enable_gui(self, gui=None): 
    451   if gui: 
--> 452    self._inputhook = get_inputhook_func(gui) 
    453   else: 
    454    self._inputhook = None 

c:\program files\python\lib\site-packages\IPython\terminal\pt_inputhooks\__init__.pyc in get_inputhook_func(gui) 
    36 
    37  if gui not in backends: 
---> 38   raise UnknownBackend(gui) 
    39 
    40  if gui in aliases: 

UnknownBackend: No event loop integration for u'inline'. Supported event loops are: qt, qt4, qt5, gtk, gtk2, gtk3, tk, wx, pyglet, glut, osx 

답변

0

내 문제는 터미널에서 플롯 이미지를 표시하는 것이 불가능합니다. jupyter notebook을 사용할 필요가있었습니다. jupyter 노트북을 설치하고 다음 명령으로 실행했습니다.

jupyter notebook 

브라우저에서 새 탭이 열립니다. 오른쪽 상단에 버튼이 있습니다.

enter image description here

가 나는 세포가 새 탭에서 파이썬 2를 선택했습니다. 각 셀에는 코드를 붙여 넣을 수 있습니다. 그것은 나를 위해 문제를 해결했다.

0

, 당신 만이 아닌 없음 인스턴스를 다시 얻을, 인라인 백엔드는 당신이하지 않을 수 있습니다 ipykernel의 일부로 제공되는 설치. inline 백엔드는 일반 프롬프트가 아닌 노트북과 qtconsole에서만 작동합니다.

+0

ipykernel 설치 후 빌드 오류로 게시물을 편집했습니다. 그리고 InteactiveShell 인스턴스를 어떻게 등록합니까? 답장을 보내 주셔서 감사합니다. – Tahlil

관련 문제