1

I am trying to add the hide_code option to my ipython notebook (jupyter, version 4, python 2.7). It is supposed to add a button or an option to the cell pull-down menu that allows me to hide the code in my ipython notebooks. I have successfully run the 'pip install hide_code' command from the terminal (MacOS X El Capitan). I have restarted the notebook and expected to see a new I have tried to restart the notebook program but nothing happens. I am not computer savvy enough to know what to do from here. Did I miss something?

Here is the github repository for the code:

https://pypi.python.org/pypi/hide_code/0.3.0

2
  • Can you create a test notebook and show us what you have as an output? Commented May 19, 2016 at 18:50
  • Hi, Well, I just have the same notebook that I have always had. I mean from the documentation I got the idea that once I installed the package the notebook would now have the option to hide the code in particular cells, either with a button or from the dropdown menu. When I ran the pip install hide_code command again from my terminal I got the following message: Requirement already satisfied (use --upgrade to upgrade): hide_code in /Users/michaelreinhard/anaconda/lib/python2.7/site-packages. Is that relevant? Commented May 19, 2016 at 19:02

2 Answers 2

1

OK I found a way to do it.

  1. Install hide_code... It will not work, though.
  2. Try to install it with (with dir="~/.ipython" or whatever)
import hide_code.hide_code as hc;
dir = "<full path to Jupyter config directory>";
hc.install(dir)

It will still not work, but it will copy a javascript file (hide_code.js) into that directory. We will use it in a bit.

  1. Let's find where those nbextensions are. Find one of them. For example, keyboard_shortcut_editor:
cd ~
find -name keyboard_shortcut_editor

Mine finds it ./.local/share/jupyter/nbextensions/keyboard_shortcut_editor Yours should be there too.

  1. Go to that directory
cd ./.local/share/jupyter/nbextensions/
ls

You see full list of various extensions. Let's copy one of them into hide_copy:

cp -r hide_input hide_code
cd hide_code
ls
  1. The important file there is main.js. Replace it with that hide_code.js from ~./ipython
cp ~./ipython/hide_code.js ./main.js
  1. Rename hide-input.yaml with hide-code.yaml and edit the content accordingly. Mainly, replace all Hide_Input references to Hide_Code. You can edit readme.md as well, but that doesn't matter. Because, the main thing, you created a new extension.

Now, if you launch your jupyter and go to http://localhost:8888/nbextensions, you will see Hide Code. And if click on that checkbox, it's on. Here are snapshots:

enter image description here

enter image description here

It is a weird sequence. But it worked for me. And the main thing, it puts it right where it needs to be. Hide_code actually needs to be a part of Nbextensions. I don't know why it is not. That way it's easy to turn it on and off any way you like it.

Sign up to request clarification or add additional context in comments.

1 Comment

That made it work via MyBinder.org/Binderhub (fancy JupyterHub) sessions based on conda. Implemented here so you won't need to.
0

As described in the documentation: https://github.com/kirbs-/hide_code, you can troubleshoot by running the following code with appropriate Jupyter config directory location:

import hide_code.hide_code as hc
dir = "<full path to Jupyter config directory>"
hc.install(dir)

4 Comments

I tried running the command in the cell of a notebook with the path to the configuration directory specified as "/Users/michaelreinahrd/jupyter/" but I get back the message: "Starting hide_code.js install... No config directories contain "custom" folder. Trying site-packages... Using argument supplied path: /Users/michaelreinhard/jupyter/ Unable to install into /Users/michaelreinhard/jupyter/ Directory doesn't exist. Make sure Jupyter installed. Attempting to configure auto-loading for hide_code export handlers. Jupyter already configured to auto-load export handlers."
The path at you are trying is incorrect. I can see you are using anaconda, please verify the path.
I tried installing it here: import hide_code.hide_code as hc dir = "/Users/michaelreinhard/.ipython/" hc.install(dir) output: Starting hide_code.js install... No config directories contain "custom" folder. Trying site-packages... Using argument supplied path: /Users/michaelreinhard/.ipython/ Copying hide_code.js to /Users/michaelreinhard/.ipython/ Attempting to configure custom.js to auto-load hide_code.js... Custom.js not in custom directory. Attempting to configure auto-loading for hide_code export handlers. Jupyter already configured to auto-load export handlers.
Is there some command I should run at the command line to 'verify the path'? Thanks. I know I am just hopeless with computers. Anyway, I'll close this question out since you have answered the basic question. Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.