Python 3.x ModuleNotFoundError:没有名为';自动加载&x27;

Python 3.x ModuleNotFoundError:没有名为';自动加载&x27;,python-3.x,jupyter,Python 3.x,Jupyter,我使用Python3内核在jupyter笔记本上运行卷积神经网络教程中的以下代码,并得到ModuleNotFoundError:没有名为“autoreload”的模块 import numpy as np import h5py import matplotlib.pyplot as plt %matplotlib inline plt.rcParams['figure.figsize'] = (5.0, 4.0) # set default size of plots p

我使用Python3内核在jupyter笔记本上运行卷积神经网络教程中的以下代码,并得到ModuleNotFoundError:没有名为“autoreload”的模块

import numpy as np
import h5py          
import matplotlib.pyplot as plt

%matplotlib inline
plt.rcParams['figure.figsize'] = (5.0, 4.0) # set default size of plots
plt.rcParams['image.interpolation'] = 'nearest'
plt.rcParams['image.cmap'] = 'gray'

%load_ext autoreload   
%autoreload 2          
np.random.seed(1)

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-3d0ea63c7843> in <module>()
      8 plt.rcParams['image.cmap'] = 'gray'
      9 
---> 10 get_ipython().magic('load_ext autoreload   # reload modules before executing user code')
     11 get_ipython().magic('autoreload 2          # Reload all modules (except those excluded by %aimport)')
     12 

/opt/conda/lib/python3.6/site-packages/IPython/core/interactiveshell.py in magic(self, arg_s)
   2156         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2157         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2158         return self.run_line_magic(magic_name, magic_arg_s)
   2159 
   2160     #-------------------------------------------------------------------------

/opt/conda/lib/python3.6/site-packages/IPython/core/interactiveshell.py 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-62> in load_ext(self, module_str)

/opt/conda/lib/python3.6/site-packages/IPython/core/magic.py 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):

/opt/conda/lib/python3.6/site-packages/IPython/core/magics/extension.py in load_ext(self, module_str)
     35         if not module_str:
     36             raise UsageError('Missing module name.')
---> 37         res = self.shell.extension_manager.load_extension(module_str)
     38 
     39         if res == 'already loaded':

/opt/conda/lib/python3.6/site-packages/IPython/core/extensions.py in load_extension(self, module_str)
     81             if module_str not in sys.modules:
     82                 with prepended_to_syspath(self.ipython_extension_dir):
---> 83                     __import__(module_str)
     84             mod = sys.modules[module_str]
     85             if self._call_load_ipython_extension(mod):

ModuleNotFoundError: No module named 'autoreload'   
将numpy导入为np
进口h5py
将matplotlib.pyplot作为plt导入
%matplotlib内联
plt.rcParams['figure.figsize']=(5.0,4.0)#设置绘图的默认大小
plt.rcParams['image.interpolation']=“最近的”
plt.rcParams['image.cmap']='gray'
%加载下一个自动加载
%自动加载2
np.随机种子(1)
---------------------------------------------------------------------------
ModuleNotFoundError回溯(上次最近调用)
在()
8 plt.rcParams['image.cmap']='gray'
9
--->10 get_ipython().magic('load_ext autoreload#在执行用户代码之前重新加载模块')
11 get_ipython().magic('autoreload 2#重新加载所有模块(由%aimport排除的模块除外)'
12
/魔术中的opt/conda/lib/python3.6/site-packages/IPython/core/interactiveshell.py(self,arg_s)
2156 magic_名称,magic_arg_s=arg_s.分区(“”)
2157 magic_name=magic_name.lstrip(prefilter.ESC_magic)
->2158返回自我。运行幻术(幻术名称、幻术参数)
2159
2160     #-------------------------------------------------------------------------
/在run\u line\u magic(self,magic\u name,line)中选择/conda/lib/python3.6/site-packages/IPython/core/interactiveshell.py
2077 kwargs['local\u ns']=sys.\u getframe(堆栈深度).f\u locals
2078带自建存水弯:
->2079结果=fn(*args,**kwargs)
2080返回结果
2081
装入外部(自身,模块)
/opt/conda/lib/python3.6/site-packages/IPython/core/magic.py in(f,*a,**k)
186#但仅仅为了那一点点国家就太过分了。
187 def魔术装饰(arg):
-->188调用=λf,*a,**k:f(*a,**k)
189
190如果可调用(arg):
/load_ext(self,module_str)中的opt/conda/lib/python3.6/site-packages/IPython/core/magics/extension.py
35如果不是模块_str:
36 raise UsageError('缺少模块名称')
--->37 res=self.shell.extension\u manager.load\u extension(模块\u str)
38
39如果res==‘已加载’:
/加载扩展中的opt/conda/lib/python3.6/site-packages/IPython/core/extensions.py(self,module\u str)
81如果模块不在系统模块中:
82带有前置的\u到\u系统路径(self.ipython\u扩展\u dir):
--->83 uuu导入uuu(模块u str)
84模=系统模件[模件]
85如果自呼叫、加载、ipython分机(mod):
ModuleNotFoundError:没有名为“autoreload”的模块

我就是找不到解决这个问题的办法。如何修复此错误?

模块autoreload属于在Jupyter上后台运行的库IPython

同样的错误也发生在我身上,这是由于空白,请参阅:


因此确保命令末尾没有空格

我遇到了同样的错误,因为我在magic命令后有一条注释:

坏的:

好:


这只是一个导入错误(隐藏在魔法中)。我猜,
导入自动登录
也会失败。您的python路径有问题。应该在路径中的某个地方通过一个
autoreload.py
,通常是在
../lib/python3.6/site packages/IPython/extensions
中。在
sys.path
中查找类似的内容。实际上,我根据您的建议找到了autoreload.py。它位于…\Lib\site packages\IPython\extensions中。还有什么原因,或者我下一步该怎么做?您是否可以使用
import autoreload
直接加载模块?扩展文件夹在sys.path中吗?哇!对我花了很多时间试图理解为什么
import autoreload
有效,为什么
%load\u ext autoreload
无效。看起来这些神奇的代码行与标准python代码行的读取方式不同!在autoreload之后,我在这行的末尾确实有一个空格!多么讨厌的错误!我也被这个问题困扰着,谢谢你给我指出了正确的方向-尾随空格确实是ipython magicsI'v的问题。我发现,即使在
%load\u ext autoreload
后留下空格也会导致错误。我可以确认@Nayef描述的行为,我有尾随空格,并且得到了相同的错误。
%load_ext autoreload # this comment should be removed
%load_ext autoreload