Python 两种形式的Jupyter笔记本的问题
最近,我在我的Jupyter笔记本上安装了Python的第二个版本,以便我可以在需要时使用Python 2或3。然而,在安装Python3之后,我在以前的python2笔记本上遇到了matplotlib、scipy和numpy的问题 打字:Python 两种形式的Jupyter笔记本的问题,python,matplotlib,ipython,jupyter-notebook,Python,Matplotlib,Ipython,Jupyter Notebook,最近,我在我的Jupyter笔记本上安装了Python的第二个版本,以便我可以在需要时使用Python 2或3。然而,在安装Python3之后,我在以前的python2笔记本上遇到了matplotlib、scipy和numpy的问题 打字: %pylab inline import time import datetime import glob import os from os import system import platform import scipy.ndimage as snd
%pylab inline
import time
import datetime
import glob
import os
from os import system
import platform
import scipy.ndimage as snd
import numpy as np
from matplotlib.pyplot import *
给我:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-fe04d06772cd> in <module>()
----> 1 get_ipython().magic(u'pylab inline')
2 import time
3 import datetime
4 import glob
5 import os
/Users/stephanng/anaconda/envs/py27/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)
2334 magic_name, _, magic_arg_s = arg_s.partition(' ')
2335 magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2336 return self.run_line_magic(magic_name, magic_arg_s)
2337
2338 #-------------------------------------------------------------------------
/Users/stephanng/anaconda/envs/py27/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in run_line_magic(self, magic_name, line)
2255 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
2256 with self.builtin_trap:
-> 2257 result = fn(*args,**kwargs)
2258 return result
2259
<decorator-gen-107> in pylab(self, line)
/Users/stephanng/anaconda/envs/py27/lib/python2.7/site-packages/IPython/core/magic.pyc in <lambda>(f, *a, **k)
191 # but it's overkill for just that one bit of state.
192 def magic_deco(arg):
--> 193 call = lambda f, *a, **k: f(*a, **k)
194
195 if callable(arg):
/Users/stephanng/anaconda/envs/py27/lib/python2.7/site-packages/IPython/core/magics/pylab.pyc in pylab(self, line)
154 import_all = not args.no_import_all
155
--> 156 gui, backend, clobbered = self.shell.enable_pylab(args.gui, import_all=import_all)
157 self._show_matplotlib_backend(args.gui, backend)
158 print ("Populating the interactive namespace from numpy and matplotlib")
/Users/stephanng/anaconda/envs/py27/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in enable_pylab(self, gui, import_all, welcome_message)
3169 from IPython.core.pylabtools import import_pylab
3170
-> 3171 gui, backend = self.enable_matplotlib(gui)
3172
3173 # We want to prevent the loading of pylab to pollute the user's
/Users/stephanng/anaconda/envs/py27/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in enable_matplotlib(self, gui)
3118 """
3119 from IPython.core import pylabtools as pt
-> 3120 gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select)
3121
3122 if gui != 'inline':
/Users/stephanng/anaconda/envs/py27/lib/python2.7/site-packages/IPython/core/pylabtools.pyc in find_gui_and_backend(gui, gui_select)
237 """
238
--> 239 import matplotlib
240
241 if gui and gui != 'auto':
ImportError: No module named matplotlib
---------------------------------------------------------------------------
ImportError回溯(最近一次呼叫最后一次)
在()
---->1 get_ipython().magic(u'pylab inline')
2导入时间
3导入日期时间
4.全球进口
5导入操作系统
/魔术版用户/stephanng/anaconda/envs/py27/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc(self,arg_)
2334 magic_名称,magic_arg_s=arg_s.分区(“”)
2335 magic_name=magic_name.lstrip(prefilter.ESC_magic)
->2336返回自我。运行\u line_umagic(魔术名称,魔术\u arg s)
2337
2338 #-------------------------------------------------------------------------
/run\u line\u magic(self,magic\u name,line)中的Users/stephanng/anaconda/envs/py27/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc
2255 kwargs['local\u ns']=sys.\u getframe(堆栈深度).f\u locals
2256带自建存水弯:
->2257结果=fn(*args,**kwargs)
2258返回结果
2259
在pylab中(自身、线路)
/(f,*a,**k)中的Users/stephanng/anaconda/envs/py27/lib/python2.7/site-packages/IPython/core/magic.pyc
191#但这一点对国家来说太过分了。
192 def魔术装饰(arg):
-->193调用=λf,*a,**k:f(*a,**k)
194
195如果可调用(arg):
/pylab中的Users/stephanng/anaconda/envs/py27/lib/python2.7/site-packages/IPython/core/magics/pylab.pyc(self,line)
154全部导入=非参数。全部不导入
155
-->156 gui,后端,clobbered=self.shell.enable_pylab(args.gui,import_all=import_all)
157 self.\u show\u matplotlib\u后端(args.gui,后端)
158打印(“从numpy和matplotlib填充交互式命名空间”)
/enable_pylab中的Users/stephanng/anaconda/envs/py27/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc(self、gui、import_all、welcome_消息)
3169从IPython.core.pylabtools导入_pylab
3170
->3171 gui,后端=self.enable_matplotlib(gui)
3172
3173#我们希望防止装载pylab污染用户的电脑
/enable_matplotlib(self,gui)中的Users/stephanng/anaconda/envs/py27/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc
3118 """
3119从IPython.core导入pylabtools作为pt
->3120 gui,backend=pt.find_gui_和_backend(gui,self.pylab_gui_select)
3121
3122如果gui!=“内联”:
/用户/stephanng/anaconda/envs/py27/lib/python2.7/site-packages/IPython/core/pylabtools.pyc在find_gui_和_backend(gui,gui_select)中
237 """
238
-->239导入matplotlib
240
241如果gui和gui!='自动':
ImportError:没有名为matplotlib的模块
我从中得到的是,在查看导入时,Python2不再指向正确的目录。如何设置正确目录的路径?不同的python用例需要不同的安装,这是一个非常常见的问题。为了避免串扰,您可以将安装分开。我完全卸载了所有内容,然后重新安装,路径得到纠正。我实际上卸载了所有内容,并重新安装了所有内容,它似乎保留了两个版本,并链接到正确的导入…一切都很好!