2016-08-02 166 views
2

我在運行jupyter nbconvert時遇到問題。執行jupyter時出現TypeError錯誤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的指示時工作。

+0

你有一個'〜/ .jupyter/jupyter_nbconvert_config.py'(或'.json')文件? –

回答

2

今天我有同樣的問題。看起來這是nbconvert中的一個錯誤,如記錄here。解決方案是編輯你的「jupyter_nbconvert_config.json」文件。對我來說,這是設在我的主目錄默認爲:/home/me/.jupyter/jupyter_nbconvert_config.json

在那裏,我改變了預處理器字符串,在他們面前添加「R」:

{ 
    "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 
} 
+0

將r添加到JSON配置中的字符串會導致JSONDecodedError。這似乎工作(等待更新版本的ipython_genutils):https://github.com/jupyter/nbconvert/issues/362#issuecomment-246169144 –

+0

爲我工作。我必須更改兩個相同的JSON文件:一個在〜/ .jupyter /中,另一個在'〜/ anaconda/etc/jupyter'中。出於某種奇怪的原因,只更改一個文件不起作用。 –

2

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

1

最近修復了這個bug,詳見here。運行完整的更新IPython中,或者手工修復:

變線在ipython_genutils 31/importstring.py從

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

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