无法加载ipython magic扩展sparkmagic:未找到模块

无法加载ipython magic扩展sparkmagic:未找到模块,python,ipython,ipython-notebook,jupyter-notebook,Python,Ipython,Ipython Notebook,Jupyter Notebook,我不熟悉将自定义magics加载到ipython中。加载的说明 火花学 扩展包括以下已成功完成的步骤: pip install sparkmagic pip show sparkmagic jupyter-kernelspec install sparkmagic/kernels/sparkkernel jupyter-kernelspec install sparkmagic/kernels/pysparkkernel jupyter-kernelspec install sparkmagic

我不熟悉将自定义
magics
加载到
ipython
中。加载的说明

火花学

扩展包括以下已成功完成的步骤:

pip install sparkmagic
pip show sparkmagic
jupyter-kernelspec install sparkmagic/kernels/sparkkernel
jupyter-kernelspec install sparkmagic/kernels/pysparkkernel
jupyter-kernelspec install sparkmagic/kernels/pyspark3kernel
jupyter-kernelspec install sparkmagic/kernels/sparkrkernel
命令
pip show sparkmagic
似乎正常:

$pip show sparkmagic
Name: sparkmagic
Version: 0.10.1
Summary: SparkMagic: Spark execution via Livy
Home-page: https://github.com/jupyter-incubator/sparkmagic/sparkmagic
Author: Jupyter Development Team
Author-email: jupyter@googlegroups.org
License: BSD 3-clause
Location: /usr/local/lib/python2.7/site-packages
Requires: mock, requests, tornado, nose, notebook, ipywidgets, ipykernel, pandas, hdijupyterutils, autovizwidget, ipython, numpy
不起作用但列为可选的东西是

$ jupyter serverextension enable --py sparkmagic

Traceback (most recent call last):
  File "/usr/local/bin/jupyter-serverextension", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/site-packages/jupyter_core/application.py", line 267, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/traitlets/config/application.py", line 658, in launch_instance
    app.start()
  File "/usr/local/lib/python3.6/site-packages/notebook/serverextensions.py", line 300, in start
    super(ServerExtensionApp, self).start()
  File "/usr/local/lib/python3.6/site-packages/jupyter_core/application.py", line 256, in start
    self.subapp.start()
  File "/usr/local/lib/python3.6/site-packages/notebook/serverextensions.py", line 217, in start
    self.toggle_server_extension_python(arg)
  File "/usr/local/lib/python3.6/site-packages/notebook/serverextensions.py", line 206, in toggle_server_extension_python
    m, server_exts = _get_server_extension_metadata(package)
  File "/usr/local/lib/python3.6/site-packages/notebook/serverextensions.py", line 334, in _get_server_extension_metadata
    m = import_item(module)
  File "/usr/local/lib/python3.6/site-packages/traitlets/utils/importstring.py", line 42, in import_item
    return __import__(parts[0])
ModuleNotFoundError: No module named 'sparkmagic'
这是堆栈跟踪(非常长)的第一部分。如果需要整个跟踪,请告诉我

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-2b579b518c56> in <module>()
----> 1 get_ipython().magic(u'load_ext sparkmagic.magics')

/usr/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)
   2161         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2162         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2163         return self.run_line_magic(magic_name, magic_arg_s)
   2164
   2165     #-------------------------------------------------------------------------

/usr/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in run_line_magic(self, magic_name, line)
   2082                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2083             with self.builtin_trap:
-> 2084                 result = fn(*args,**kwargs)
   2085             return result
   2086

<decorator-gen-64> in load_ext(self, module_str)

/usr/local/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):

/usr/local/lib/python2.7/site-packages/IPython/core/magics/extension.pyc in load_ext(self, module_str)
     64         if not module_str:
     65             raise UsageError('Missing module name.')
---> 66         res = self.shell.extension_manager.load_extension(module_str)
     67
     68         if res == 'already loaded':
---------------------------------------------------------------------------
AttributeError回溯(最近一次呼叫上次)
在()
---->1 get_ipython().magic(u'load_ext sparkmagic.magics'))
/魔术中的usr/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc(self,arg_s)
2161 magic_名称,magic_arg_s=arg_s.分区(“”)
2162 magic_name=magic_name.lstrip(prefilter.ESC_magic)
->2163返回自我。运行幻术(幻术名称,幻术参数)
2164
2165     #-------------------------------------------------------------------------
/usr/local/lib/python2.7/site-packages/IPython/core/interactivesewell.pyc in run\u line\u magic(self,magic\u name,line)
2082 kwargs['local\u ns']=sys.\u getframe(堆栈深度).f\u locals
2083带自建存水弯:
->2084结果=fn(*args,**kwargs)
2085返回结果
2086
装入外部(自身,模块)
/usr/local/lib/python2.7/site-packages/IPython/core/magic.pyc in(f,*a,**k)
191#但这一点对国家来说太过分了。
192 def魔术装饰(arg):
-->193调用=λf,*a,**k:f(*a,**k)
194
195如果可调用(arg):
/加载扩展中的usr/local/lib/python2.7/site-packages/IPython/core/magics/extension.pyc(self,module_str)
64如果不是模块_str:
65 raise UsageError('缺少模块名称')
--->66 res=self.shell.extension\u manager.load\u extension(模块\u str)
67
68如果res==‘已加载’:

总之,安装/使用任何magics都可能需要一个步骤。非常感谢指针。

从您的错误和安装消息中我看到,您安装了python2.7的spark magic,并试图在Python3.6中运行它。这让人困惑,当我开始的时候,我也有同样的问题很多次。我建议您通过运行
来检查您正在使用的python版本!python——笔记本上的版本
。如果它是python的正确版本,那么使用
安装sparkmagic!pip安装sparkmagic
,并检查安装消息是否安装到正确的python版本


你也可以建立一个环境,让生活更轻松。这里的更多内容

看起来像是
jupyter
正在接受
3.6
ipython
python
将进入
2.7.x
。让我来解决一下,然后回去。我在这里投票给初学者。好的,是的,这是引起问题的原因:第一行是
#/usr/local/opt/python3/bin/python3.6
。这是一个问题:我们在
2.7
中工作:将研究如何做。我需要
pip安装--强制重新安装jupyter
,以清除所有问题。您可以同时使用2.7和3.6吗?在我的机器上,我将2.7、3.5和3.6安装在一起。我所做的就是为每种Python类型启动一个环境。看这段视频,它会很有帮助,让事情变得容易。
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-2b579b518c56> in <module>()
----> 1 get_ipython().magic(u'load_ext sparkmagic.magics')

/usr/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)
   2161         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2162         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2163         return self.run_line_magic(magic_name, magic_arg_s)
   2164
   2165     #-------------------------------------------------------------------------

/usr/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in run_line_magic(self, magic_name, line)
   2082                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2083             with self.builtin_trap:
-> 2084                 result = fn(*args,**kwargs)
   2085             return result
   2086

<decorator-gen-64> in load_ext(self, module_str)

/usr/local/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):

/usr/local/lib/python2.7/site-packages/IPython/core/magics/extension.pyc in load_ext(self, module_str)
     64         if not module_str:
     65             raise UsageError('Missing module name.')
---> 66         res = self.shell.extension_manager.load_extension(module_str)
     67
     68         if res == 'already loaded':