kirbs- / hide_code

Code, prompt and output hiding for Jupyter/IPython notebooks.
MIT License
371 stars 44 forks source link

Error exporting with changed notebook_dir #38

Closed juanep97 closed 7 years ago

juanep97 commented 7 years ago

Hello,

I have python 2.7.11-1 on Ubuntu 16.04 and ipython-2.4.1-1 and jupyter (pip-installed).

I changed /home/user/.jupyter/jupyter_notebook_config.py from: c.NotebookApp.notebook_dir = u'' to c.NotebookApp.notebook_dir = u'/home/user/Workspace/Python' so that it starts in such folder automatically. However this seems to break hidecode. When exporting a notebook (for example, with html), it gives a 500 Internal Server Error in the browser and the following output:

[I 12:47:03.980 NotebookApp] hide_code: Starting HTML export for None
[E 12:47:03.981 NotebookApp] Uncaught exception GET /notebooks/Untitled.ipynb/export/html (127.0.0.1)
    HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/notebooks/Untitled.ipynb/export/html', version='HTTP/1.1', remote_ip='127.0.0.1', headers={'Accept-Language': 'en-US,en;q=0.5', 'Accept-Encoding': 'gzip, deflate', 'Host': 'localhost:8888', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0', 'Connection': 'keep-alive', 'Referer': 'http://localhost:8888/notebooks/Untitled.ipynb', 'Cookie': '_xsrf=2|4ef5945a|837a269c7a3908ca679866b46ba8453d|1490950765; username-localhost-8888="2|1:0|10:1490957216|23:username-localhost-8888|44:MmI5ODEzMzE0OGY4NDhkM2FlODE0NzRlM2Q3NGZiYjM=|79cb9ba85c1293bd5c057c4d5cc0bc903cf48a495567407a83bd95ec1e8d832a"', 'Upgrade-Insecure-Requests': '1'})
    Traceback (most recent call last):
      File "/usr/lib/python2.7/dist-packages/tornado/web.py", line 1413, in _execute
        result = method(*self.path_args, **self.path_kwargs)
      File "/usr/local/lib/python2.7/dist-packages/hide_code/hide_code.py", line 23, in get
        with open(ipynb_file_name(args)) as f:
    IOError: [Errno 2] No such file or directory: u'Untitled.ipynb'

It seems that hidecode cannot find the notebook file, at the time of execution of /usr/local/lib/python2.7/dist-packages/hide_code/hide_code.py. The argument args of the get method of HideCodeHTMLExportHandler does not seem to contain the full path to the notebook file, so I think that is the problem (the change applied to jupyter configuration file is not reflected here).

I don't know if this is intended behavior but I thought I would report it anyway, as it is a bit irksome. If there is anyway to fix it or a work around I would like to know.

Thank you. This extension is definitely useful.

kirbs- commented 7 years ago

What version of hide_code are you using and did you install via nbextensions?

juanep97 commented 7 years ago

Hello, This is the output of pip show hide_code:

Name: hide-code
Version: 0.4.0
Summary: A Jupyter notebook extension to hide code, prompts and outputs.
Home-page: https://github.com/kirbs-/hide_code
Author: Chris Kirby
Author-email: kirbycm@gmail.com
License: MIT
Location: /usr/local/lib/python2.7/dist-packages
Requires: jupyter, pdfkit, nbconvert

I installed it executing:

pip install hide_code
jupyter nbextension install --py hide_code
jupyter nbextension enable --py hide_code
jupyter serverextension enable --py hide_code

I also reinstalled it with the --sys-prefix to see if that was the reason, to no avail.

kirbs- commented 7 years ago

Not sure what's wrong here. Hide_code is using Jupyter's paths to access the underlying .ipynb file. If you navigate to http://localhost:8888/notebooks/Untitled.ipynb does the notebook open up?

juanep97 commented 7 years ago

Yes, it does open. Have you confirmed the bug or is something affecting my installation solely?

kirbs- commented 7 years ago

It's a bug. Looks like the jupyter method I'm using to find the underlying file is a relative path. I'll have to do some digging in Jupyter's documentation to find an alternative.