Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nbconvert fails with unicode preprocessor names #362

Closed
juhasch opened this issue Aug 15, 2016 · 7 comments
Closed

nbconvert fails with unicode preprocessor names #362

juhasch opened this issue Aug 15, 2016 · 7 comments
Milestone

Comments

@juhasch
Copy link
Contributor

juhasch commented Aug 15, 2016

I get the following error with nbconvert after installing custom preprocessors available in jupyter_contrib_nbextensions from conda-forge into a Python 2.7 environment:

Traceback (most recent call last):
  File "/home/juhasch/anaconda3/envs/py27/bin/jupyter-nbconvert", line 6, in <module>
    main()
  File "/home/juhasch/anaconda3/envs/py27/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/juhasch/anaconda3/envs/py27/lib/python2.7/site-packages/traitlets/config/application.py", line 596, in launch_instance
    app.start()
  File "/home/juhasch/anaconda3/envs/py27/lib/python2.7/site-packages/nbconvert/nbconvertapp.py", line 293, in start
    self.convert_notebooks()
  File "/home/juhasch/anaconda3/envs/py27/lib/python2.7/site-packages/nbconvert/nbconvertapp.py", line 447, in convert_notebooks
    self.exporter = cls(config=self.config)
  File "/home/juhasch/anaconda3/envs/py27/lib/python2.7/site-packages/nbconvert/exporters/templateexporter.py", line 151, in __init__
    super(TemplateExporter, self).__init__(config=config, **kw)
  File "/home/juhasch/anaconda3/envs/py27/lib/python2.7/site-packages/nbconvert/exporters/exporter.py", line 101, in __init__
    self._init_preprocessors()
  File "/home/juhasch/anaconda3/envs/py27/lib/python2.7/site-packages/nbconvert/exporters/exporter.py", line 251, in _init_preprocessors
    self.register_preprocessor(preprocessor, enabled=True)
  File "/home/juhasch/anaconda3/envs/py27/lib/python2.7/site-packages/nbconvert/exporters/exporter.py", line 212, in register_preprocessor
    preprocessor_cls = import_item(preprocessor)
  File "/home/juhasch/anaconda3/envs/py27/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

It looks like this is a unicode problem with Python 2.7. This is the default jupyter_nbconvert_config.json file:

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

Adding r to the preprocessor strings makes it work again:

{
  "Exporter": {
    "template_path": [
      ".", 
      "/home/juhasch/anaconda3/envs/py27/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
}

Nbconvert version is 4.2.0 on Linux Mint.

@takluyver
Copy link
Member

Won't adding an r prefix just make it invalid JSON, resulting in it not using that file at all?

@juhasch
Copy link
Contributor Author

juhasch commented Aug 17, 2016

I don't think adding an 'r' is a solution. I get similar errors when I remove the prepocessor part, too.
So somehow the JSON files are seen as Unicode and ipython_genutils doesn't like that for Python 2.7.
Maybe it is a Linux Mint problem. This is where I get the error.

Any ideas what to look for ?

@takluyver
Copy link
Member

JSON is conceptually unicode, and I think the JSON module leans towards returning parsed JSON strings as unicode. I guess you're probably just the first person to run into this: importable names listed in a JSON config file, parsed by Python 2.

@agreicius
Copy link

Thanks so much, @juhasch ! I had the exact same problems with nbconvert after installing the same nbextensions collection you mention, and after copying and pasting your edits all is good. (Probably not the correct way to use github, but it worked!)

@mpacer
Copy link
Member

mpacer commented Aug 29, 2016

Am I correct in saying that #370 addresses this?

@agreicius
Copy link

agreicius commented Aug 29, 2016

Not sure if @michaelpacer 's question was directed at me, but to be specific, after making the changes described in the following two commits, the problem was fixed/

  1. ipython/ipython_genutils@3d47e88
  2. f01e44d

@arogozhnikov
Copy link

Not sure if @michaelpacer 's question was directed at me, but to be specific, after making the changes described in the following two commits, the problem was fixed/

Thanks a lot, this fix was enough for me:

  1. ipython/ipython_genutils@3d47e88

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants