nbconvert template paths

539 views
Skip to first unread message

Tony Hirst

unread,
Nov 28, 2015, 3:35:24 AM11/28/15
to Project Jupyter
If I try to use nbconvert with a custom template by either of:

jupyter nbconvert --config=my_config.py --log-level=DEBUG Untitled.ipynb
jupyter nbconvert --template=my_template.tpl --log-level=DEBUG Untitled.ipynb

I can only get it to work if the custom file is in the same directory.

If I use the config route with:

#---
from jupyter_core.paths import jupyter_data_dir
extensiondir=os.path.join(jupyter_data_dir(),'nbextensions/myextension/')

c = get_config()
c.TemplateExporter.template_path = [ extensiondir ]
c.TemplateExporter.template_file = 'my_template.tpl'
#---

I can relocate the template file but the config file needs to be in the local directory.

The debug trace suggests that there re not paths down down which the script looks for the config file?

[NbConvertApp] Config changed:
[NbConvertApp] {'NbConvertApp': {'log_level': 'DEBUG', 'config_file': 'ipython_nbconvert_config2.py'}}
[NbConvertApp] Searching ['/vagrant/notebooks', '/root/.jupyter', '/usr/etc/jupyter', '/usr/local/etc/jupyter', '/etc/jupyter'] for config files
[NbConvertApp] Attempting to load config file jupyter_config.py in path /etc/jupyter
[NbConvertApp] Attempting to load config file jupyter_config.json in path /etc/jupyter
[NbConvertApp] Attempting to load config file jupyter_config.py in path /usr/local/etc/jupyter
[NbConvertApp] Attempting to load config file jupyter_config.json in path /usr/local/etc/jupyter
[NbConvertApp] Attempting to load config file jupyter_config.py in path /usr/etc/jupyter
[NbConvertApp] Attempting to load config file jupyter_config.json in path /usr/etc/jupyter
[NbConvertApp] Attempting to load config file jupyter_config.py in path /root/.jupyter
[NbConvertApp] Attempting to load config file jupyter_config.json in path /root/.jupyter
[NbConvertApp] Attempting to load config file jupyter_config.py in path /vagrant/notebooks
[NbConvertApp] Attempting to load config file jupyter_config.json in path /vagrant/notebooks
[NbConvertApp] Attempting to load config file ipython_nbconvert_config2.py in path 
[NbConvertApp] Attempting to load config file ipython_nbconvert_config2.json in path 
[NbConvertApp] Converting notebook Untitled.ipynb to html

That is, the path is empty?

My workaround is to copy the template file into the local dir, run with that, and then delete the local template file. Which I'm sure is not the way to do it properly?!

Willy Rempel

unread,
Apr 15, 2018, 5:00:12 PM4/15/18
to Project Jupyter
So was an answer ever provided? I am trying to get this going myself. 
Especially since templates can depend on other templates. 
IE. the nbconvert_examples repo has dependencies. I can't get any to work, unless perhaps I copy a dozen templates, including the defaults, all into the working directory
Reply all
Reply to author
Forward
0 new messages