question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Permission Denied error when invoking show() from inside Jupyter Notebook

See original GitHub issue

Hi,

I’m using bokeh 0.12.3 and jupyter 1.0.0. I’m writing some code that produces a simple bar chart and calls show() on this bar chart inside the notebook.

Here’s the backtrace that I get:

PermissionError                           Traceback (most recent call last)
<ipython-input-3-e94210215dfe> in <module>()
      1 results = r._get_results()
----> 2 v.visualize(results, None, None)

/home/lukas/src/tcpsp/TCPSPsuite/scripts/visualizer.py in visualize(self, results, x_axis, y_axis)
     11         chart = Bar(df, 'job_count', values='elapsed', agg='mean')
     12 
---> 13         show(chart)

/home/lukas/.virtualenvs/tcpsp/lib/python3.5/site-packages/bokeh/io.py in show(obj, browser, new, notebook_handle)
    312     if obj not in _state.document.roots:
    313         _state.document.add_root(obj)
--> 314     return _show_with_state(obj, _state, browser, new, notebook_handle=notebook_handle)
    315 
    316 

/home/lukas/.virtualenvs/tcpsp/lib/python3.5/site-packages/bokeh/io.py in _show_with_state(obj, state, browser, new, notebook_handle)
    330 
    331     if state.file or not shown:
--> 332         _show_file_with_state(obj, state, new, controller)
    333 
    334     return comms_handle

/home/lukas/.virtualenvs/tcpsp/lib/python3.5/site-packages/bokeh/io.py in _show_file_with_state(obj, state, new, controller)
    335 
    336 def _show_file_with_state(obj, state, new, controller):
--> 337     filename = save(obj, state=state)
    338     controller.open("file://" + filename, new=_new_param[new])
    339 

/home/lukas/.virtualenvs/tcpsp/lib/python3.5/site-packages/bokeh/io.py in save(obj, filename, resources, title, state, validate)
    394 
    395     filename, resources, title = _get_save_args(state, filename, resources, title)
--> 396     _save_helper(obj, filename, resources, title, validate)
    397     return os.path.abspath(filename)
    398 

/home/lukas/.virtualenvs/tcpsp/lib/python3.5/site-packages/bokeh/io.py in _save_helper(obj, filename, resources, title, validate)
    462         html = standalone_html_page_for_models(obj, resources, title)
    463 
--> 464         with io.open(filename, "w", encoding="utf-8") as f:
    465             f.write(decode_utf8(html))
    466 

PermissionError: [Errno 13] Permission denied: '/usr/lib/python3.5/runpy.html'

It seems like I’m not the only one experiencing the problem: see for example https://github.com/yhat/rodeo/issues/211

I’m pretty sure the problem is in _detect_filename() in io.py: If no filename to save a chart to is supplied, it tries to save the file (with an autodetected filename) into the directory of the currently executing file (more exactly: the file executing in the topmost stackframe, which is assumed to be the main file being run.) This fails spectacularly if that file is located in a read-only location as is the case when you run an jupyter notebook, which on my system seems to use “/usr/lib/python3.5/runpy.py” to run the notebook.

I think the cleanest solution would be to use a temporary directory if no save-to directory is specified. If no directory is specified, the user is probably not really interested in the file, but only needs it temporarily: This happens in the show() method, for example.

Is there a reason for saving temporary files in the directory of the script? In that case, should the save() method be amended by a “temporary” argument (with default False), which in turn tells _detect_filename() to use a temporary directory? In that case, show() could set that flag and avoid the permission problem…?

I’d be willing to cook up a pull request if I get any feedback on how you think this problem should be solved.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:16 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
bryevdvcommented, Jan 28, 2017

@tinloaf A PR would be appreciated, are you still interested in working on one?

My personal preference would just be to always use a writable temp file. I think the observation that if someone is calling show without output_file, they they probably just want to see the result in a browser, and don’t really care about a file, is correct. I think that behavior would actually fill in a capability gap that currently exists. This approach would also be simple to implement, explain, and avoid magic.

@mattpap @almarklein does that sound ok? I think wanting show to “just work” i.e. open a browser with the output without a filename is reasonable. But I also think if you do want the file, it is not too much to require that the filename be specified to mark that interest (i.e. with output_file).

0reactions
jsignellcommented, Mar 1, 2017

@bryevdv I see now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot open new Jupyter Notebook [Permission Denied]
It opens and shows a list of current path directories. But I cannot create a new notebook(Python3). It says. Unexpected error while saving...
Read more >
[Errno 13] Permission denied · Issue #4907 · jupyter/notebook
Hi, I just created today a new kernel in Windows (native not WSL) and all my notebooks stopped working with the Error 13...
Read more >
How to fix PermissionError in Jupyter Notebooks - YouTube
Here is the outline of the whole video: 00:00 :Type the code producing error 00:15 :Probably you use some antivirus which is protecting...
Read more >
Error: Creating Notebook Failed. An error occurred while ...
An error occurred while creating a new notebook. Permission denied: <notebook_name>.ipynb. Error Message. Various ArcGIS modules can be used ...
Read more >
Cannot open new Jupyter Notebook [Permission Denied]
I have installed Jupyter Notebook on ubuntu 16.04 using pip3. I can execute jupyter notebook command. It opens and shows a list of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found