执行jupyter nbconvert时的TypeError

时间:2016-08-02 14:51:49

标签: jupyter jupyter-notebook nbconvert

我在运行jupyter nbconvert时遇到了问题。

它总是显示以下错误跟踪(即使是带有少量香草单元的笔记本)

Traceback (most recent call last):
  File "/home/miguel/.virtualenvs/ipython/bin/jupyter-nbconvert", line 11, in <module>
    sys.exit(main())
  File "/home/miguel/.virtualenvs/ipython/local/lib/python2.7/site-packages/jupyter_core/application.py", line 267, in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/home/miguel/.virtualenvs/ipython/local/lib/python2.7/site-packages/traitlets/config/application.py", line 596, in launch_instance
    app.start()
  File "/home/miguel/.virtualenvs/ipython/local/lib/python2.7/site-packages/nbconvert/nbconvertapp.py", line 293, in start
    self.convert_notebooks()
  File "/home/miguel/.virtualenvs/ipython/local/lib/python2.7/site-packages/nbconvert/nbconvertapp.py", line 447, in convert_notebooks
    self.exporter = cls(config=self.config)
  File "/home/miguel/.virtualenvs/ipython/local/lib/python2.7/site-packages/nbconvert/exporters/templateexporter.py", line 151, in __init__
    super(TemplateExporter, self).__init__(config=config, **kw)
  File "/home/miguel/.virtualenvs/ipython/local/lib/python2.7/site-packages/nbconvert/exporters/exporter.py", line 101, in __init__
    self._init_preprocessors()
  File "/home/miguel/.virtualenvs/ipython/local/lib/python2.7/site-packages/nbconvert/exporters/exporter.py", line 250, in _init_preprocessors
    self.register_preprocessor(preprocessor, enabled=True)
  File "/home/miguel/.virtualenvs/ipython/local/lib/python2.7/site-packages/nbconvert/exporters/exporter.py", line 211, in register_preprocessor
    preprocessor_cls = import_item(preprocessor)
  File "/home/miguel/.virtualenvs/ipython/local/lib/python2.7/site-packages/ipython_genutils/importstring.py", line 31, in import_item
    module = __import__(package, fromlist=[obj])
TypeError: Item in ``from list'' not a string

它可能与我最近安装的nbextensions有关,因为几天前jupyter nbconvert命令用来完美地工作。

今天,我在安装nbextensions时遇到了一些麻烦。我尝试使用conda,但最后我按照here的说明进行了操作。

3 个答案:

答案 0 :(得分:2)

我今天遇到了同样的问题。这似乎是nbconvert中的一个错误,正如文档here所述。解决方案是编辑你的&#34; jupyter_nbconvert_config.json&#34;文件。对我来说,默认情况下它位于我的主目录中:/home/me/.jupyter/jupyter_nbconvert_config.json

在那里,我更改了预处理器字符串,添加了&#34; r&#34;在他们面前:

{
  "Exporter": {
    "template_path": [
      ".", 
      "/usr/lib/python2.7/site-    packages/jupyter_contrib_nbextensions/templates"
    ], 
    "preprocessors": [
      r"jupyter_contrib_nbextensions.nbconvert_support.CodeFoldingPreprocessor", 
      r"jupyter_contrib_nbextensions.nbconvert_support.PyMarkdownPreprocessor"
    ]
  }, 
  "NbConvertApp": {
    "postprocessor_class":     "jupyter_contrib_nbextensions.nbconvert_support.EmbedPostProcessor"
  }, 
  "version": 1
}

答案 1 :(得分:2)

找到解决方案here。 基本上,您需要删除或重命名您的jupyter_nbconvert_config文件。

答案 2 :(得分:1)

此错误最近已修复,请参阅详细信息here。运行ipython的完整更新,或手动修复:

来自

的ipython_genutils / importstring.py

更改第31行

module = __import__(package, fromlist=[obj])     

module = __import__(package, fromlist=[str(obj)])