从jupyter笔记本导入matplotlib失败,而命令行python交互模式工作
我正在使用venv从jupyter笔记本导入matplotlib失败,而命令行python交互模式工作,python,matplotlib,jupyter-notebook,jupyter,Python,Matplotlib,Jupyter Notebook,Jupyter,我正在使用venv python --version Python 3.6.1 pip3 version: pip 9.0.1 from /Users/zhiyin/ml/venv3.6/lib/python3.6/site-packages (python 3.6) import matplotlib在python shell中工作 但是,在jupyter模式下,它会失败,并出现以下错误: --------------------------------------------
python --version
Python 3.6.1
pip3 version:
pip 9.0.1 from /Users/zhiyin/ml/venv3.6/lib/python3.6/site-packages (python 3.6)
import matplotlib
在python shell中工作
但是,在jupyter模式下,它会失败,并出现以下错误:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-3-d1ff1f5634e7> in <module>()
1 # Render our plots inline
----> 2 get_ipython().magic('matplotlib inline')
3
4 import pandas as pd
5 import matplotlib.pyplot as plt
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/interactiveshell.py in magic(self, arg_s)
2144 magic_name, _, magic_arg_s = arg_s.partition(' ')
2145 magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2146 return self.run_line_magic(magic_name, magic_arg_s)
2147
2148 #-------------------------------------------------------------------------
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line)
2065 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
2066 with self.builtin_trap:
-> 2067 result = fn(*args,**kwargs)
2068 return result
2069
<decorator-gen-107> in matplotlib(self, line)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
185 # but it's overkill for just that one bit of state.
186 def magic_deco(arg):
--> 187 call = lambda f, *a, **k: f(*a, **k)
188
189 if callable(arg):
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/magics/pylab.py in matplotlib(self, line)
97 print("Available matplotlib backends: %s" % backends_list)
98 else:
---> 99 gui, backend = self.shell.enable_matplotlib(args.gui)
100 self._show_matplotlib_backend(args.gui, backend)
101
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-
packages/IPython/core/interactiveshell.py in enable_matplotlib(self, gui)
2916 """
2917 from IPython.core import pylabtools as pt
-> 2918 gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select)
2919
2920 if gui != 'inline':
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/pylabtools.py in find_gui_and_backend(gui, gui_select)
267 """
268
--> 269 import matplotlib
270
271 if gui and gui != 'auto':
ModuleNotFoundError: No module named 'matplotlib'
---------------------------------------------------------------------------
ModuleNotFoundError回溯(上次最近调用)
在()
1#在线渲染我们的绘图
---->2 get_ipython().magic('matplotlib inline')
3.
4进口熊猫作为pd
5导入matplotlib.pyplot作为plt
/magic中的Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/interactiveshell.py(self,arg_s)
2144 magic_名称,magic_arg_s=arg_s.分区(“”)
2145 magic_name=magic_name.lstrip(prefilter.ESC_magic)
->2146返回自我。运行幻术(幻术名称,幻术参数)
2147
2148 #-------------------------------------------------------------------------
/run\u line\u magic(self,magic\u name,line)中的Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/interactiveshell.py
2065 kwargs['local\u ns']=sys.\u getframe(堆栈深度).f\u locals
2066带自建存水弯:
->2067结果=fn(*args,**kwargs)
2068返回结果
2069
在matplotlib中(自身,行)
/(f,*a,**k)中的Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/magic.py
185#但就这一点来说就太过分了。
186 def魔术装饰(arg):
-->187调用=λf,*a,**k:f(*a,**k)
188
189如果可调用(arg):
/matplotlib中的Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/magics/pylab.py(self,line)
97打印(“可用matplotlib后端:%s”%backends\u列表)
98其他:
--->99 gui,backend=self.shell.enable_matplotlib(args.gui)
100 self.\u show\u matplotlib\u后端(args.gui,后端)
101
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-
enable_matplotlib(self,gui)中的packages/IPython/core/interactiveshell.py
2916 """
2917从IPython.core导入pylabtools作为pt
->2918 gui,backend=pt.find_gui_和_backend(gui,self.pylab_gui_select)
2919
2920如果gui!=“内联”:
/find_gui_和_backend(gui,gui_select)中的Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/pylabtools.py
267 """
268
-->269导入matplotlib
270
271如果gui和gui!='自动':
ModuleNotFoundError:没有名为“matplotlib”的模块
在pythonshell和jupyter中,sys.path的值是多少,shell:'PATH':'/Users/zhiyin/ml/venv3.6/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Frameworks/3.6/bin:/Python.framework/Versions/3.5/bin:/Users/zhiyin/Library/meld-osx-9:/usr/local/bin:/usr/bin:/usr/sbin:/os.environment,Jupyter笔记本中的路径,“/Library/Frameworks/Python.framework/Versions/3.6/bin:/Users/zhiyin/ml/venv3.6/bin:/Library/Frameworks/Versions/2.7/bin:/Library/Frameworks/3.6/bin:/Library/Frameworks/Python.Frameworks/Versions/3.5/bin:/Users/zhiyin/Library/meld-osx-9:/usr/local/bin:/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/sbin:/shell:sys.path中的”在jupyter,sys.path是:['',/Library/Frameworks/Python.Frameworks/Versions/3.6/lib/Python.6','/Library/Frameworks/Python.Frameworks/Python.framework/Versions/3.6/lib/Python.36.zip','/Users/zhiyin/ml/venv3.6/lib/Python.6/site packages'][“”,/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip',“/Library/Frameworks/python3.6',”/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload',“/Library/Frameworks/python3.6/Versions/site-packages',”/Library/Frameworks/python3.6/python3.6/site-packagesions/3.6/lib/python3.6/site packages/IPython/extensions','/Users/zhiyin/.IPython']