Closed kmallick2000 closed 7 years ago
Try starting jupyter with jupyter notebook --NotebookApp.server_extensions="['hide_code.hide_code']"
Edit: fixed typo
I tried
jupyter notebook --NotebookApp.server_extensions="['hide_code.hide_code']"
and got
[C 12:01:06.138 NotebookApp] Bad config encountered during initialization:
[C 12:01:06.139 NotebookApp] The 'server_extensions' trait of a NotebookApp instance must be a list, but a value of type 'unicode' (i.e. u"[hide_code.hide_code']") was specified.
And now the icons for html and pdf etc have gone missing from the toolbar.
You have a typo here ...f type 'unicode' (i.e. u"[hide_code.hide_code']") was specified.
Make sure the hide_code.hide_code is wrapped in single quotes. It should look like this jupyter notebook --NotebookApp.server_extensions="['hide_code.hide_code']"
sorry about that. now that command goes through and it opens jupyer notebook, but I don't see the icons to hide code, export to html and pdf etc.
I tried the same in Windows 10 and I confirm that the export to html or pdf is not hiding the code. Now if I can get the icons to show up in linux, I can try again there.
Can you post pip's output when installing hide_code and the first 5-10 lines console lines when jupyter's console?
I ran pip install hide_code again. This is the output:
Requirement already satisfied: hide_code in ./anaconda2/lib/python2.7/site-packages
Requirement already satisfied: jupyter in ./anaconda2/lib/python2.7/site-packages (from hide_code)
Requirement already satisfied: pdfkit in ./anaconda2/lib/python2.7/site-packages (from hide_code)
Here is the output from starting jupyter notebook --NotebookApp.server_extensions="['hide_code.hide_code']"
[I 15:59:42.720 NotebookApp] [nb_conda_kernels] enabled, 2 kernels found
[I 15:59:43.029 NotebookApp] The port 8888 is already in use, trying another port.
[I 15:59:43.029 NotebookApp] The port 8889 is already in use, trying another port.
[I 15:59:43.030 NotebookApp] The port 8890 is already in use, trying another port.
[I 15:59:43.030 NotebookApp] The port 8891 is already in use, trying another port.
[I 15:59:43.899 NotebookApp] [nb_anacondacloud] enabled
[I 15:59:43.903 NotebookApp] [nb_conda] enabled
[I 15:59:43.954 NotebookApp] ✓ nbpresent HTML export ENABLED
[W 15:59:43.954 NotebookApp] ✗ nbpresent PDF export DISABLED: No module named nbbrowserpdf.exporters.pdf
[I 15:59:43.968 NotebookApp] Serving notebooks from local directory: /home/kaushik
[I 15:59:43.968 NotebookApp] 0 active kernels
[I 15:59:43.968 NotebookApp] The Jupyter Notebook is running at: http://localhost:8892/?token=48d551b326c0c71ee5f58d9a2f2974a5ca6490ddc6127fb5
[I 15:59:43.968 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 15:59:43.969 NotebookApp]
I don't see the hide_code's server extension getting loaded. You should this in the consoles first few lines.
[I 17:50:32.879 NotebookApp] hide_code: Attempting to load hid_code export handler extensions.
[I 17:50:32.881 NotebookApp] hide_code: Hide_code export handler extensions loaded.
Would you post the jupyter and notebook versions your using pip list | grep 'jupyter'
and pip list | grep 'notebook'
. Jupyter notebook release 4.3 about a month ago.
Jupyter is 1.0.0 and notebook is 4.3.1.
I killed all running jupyter kernels and notebook processes. I restarted a jupyter notebook using
jupyter notebook --NotebookApp.server_extensions="['hide_code.hide_code']"
Here is the output and it seems the hide_code's server extension is getting loaded fine. But I don't see any of the icons for hiding code, export to html or pdf.
[W 23:35:52.767 NotebookApp] server_extensions is deprecated, use nbserver_extensions
[I 23:35:53.629 NotebookApp] [nb_conda_kernels] enabled, 2 kernels found
[I 23:35:53.989 NotebookApp] The port 8888 is already in use, trying another port.
[I 23:35:54.043 NotebookApp] hide_code: Attempting to load hid_code export handler extensions.
[I 23:35:54.045 NotebookApp] hide_code: Hide_code export handler extensions loaded.
[I 23:35:54.945 NotebookApp] [nb_anacondacloud] enabled
[I 23:35:54.949 NotebookApp] [nb_conda] enabled
[I 23:35:54.950 NotebookApp] ✓ nbpresent HTML export ENABLED
[W 23:35:54.950 NotebookApp] ✗ nbpresent PDF export DISABLED: No module named nbbrowserpdf.exporters.pdf
[I 23:35:54.964 NotebookApp] Serving notebooks from local directory: /home/kaushik/notebooks
[I 23:35:54.964 NotebookApp] 0 active kernels
[I 23:35:54.964 NotebookApp] The Jupyter Notebook is running at: http://localhost:8889/?token=88fed589d563c3de68ca2f1954ab3af0b0e052dfd64d4240
[I 23:35:54.964 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 23:35:54.968 NotebookApp]
Run python -c "import hide_code; print hide_code.setup_info()"
You should get the output below if everything installed correctly.
Installation dir: /Users/kirbs-/.virtualenvs/ipython-2.7.10/lib/python2.7/site-packages/hide_code
Configuration dir: /Users/kirbs-/.jupyter
Export handler extensions: Loaded
Hide Code files: ['__init__.py', '__init__.pyc', 'auto-load-server-extension.txt', 'auto-load.txt', 'hide_code.js', 'hide_code.py', 'hide_code.pyc', 'hide_code_config.json', 'hide_code_config.py', 'hide_code_config.pyc', 'hide_code_html_exporter.py', 'hide_code_html_exporter.pyc', 'hide_code_pdf_exporter.py', 'hide_code_pdf_exporter.pyc', 'hide_code_preprocessor.py', 'hide_code_preprocessor.pyc', 'LICENSE.txt', 'utils.py', 'utils.pyc']
Custom JS contents:
define([
'base/js/events'
],
function(events) {
events.on('app_initialized.NotebookApp', function(){
require(['custom/hide_code']);
});
});
If you don't see any export buttons on the toolbar the Custom JS contents:
section may be blank.
Thanks again. Yes, you are right, I ran
python -c "import hide_code; print hide_code.setup_info()"
and Custom JS contents is indeed blank. How come it is missing and how can I get it back?
Try running python -c "import hide_code.hide_code as hc; hc.install()"
I am sorry, still no luck. Here is the output from running python -c "import hide_code.hide_code as hc; hc.install()"
Starting hide_code.js install...
Copying hide_code.js to /home/kaushik/.jupyter/custom
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.
I checked and Custom.js is showing in the /home/kaushik/.jupyter/custom folder.
hide_code is installing itself in /home/kaushik/.jupyter/custom
, but the installer doesn't see a custom.js file. Do you see this file in /<installation dir>/static/custom/
? Where <installation dir>
is the same installation directory from python -c "import hide_code; print hide_code.setup_info()"
I am providing the output of python -c "import hide_code; print hide_code.setup_info()"
below. And yes I see a custom.js in home/kaushik/anaconda2/lib/python2.7/site-packages/hide_code.
What can I do?
Installation dir: /home/kaushik/anaconda2/lib/python2.7/site-packages/hide_code
Configuration dir: /home/kaushik/.jupyter
Export handler extensions: Loaded
Hide Code files: ['__init__.py', 'hide_code.py', 'hide_code_config.py', 'hide_code_html_exporter.py', 'hide_code_pdf_exporter.py', 'hide_code_preprocessor.py', 'utils.py', 'hide_code.js', 'auto-load-server-extension.txt', 'auto-load.txt', 'LICENSE.txt', 'hide_code_config.json', '__init__.pyc', 'hide_code.pyc', 'hide_code_config.pyc', 'hide_code_html_exporter.pyc', 'hide_code_pdf_exporter.pyc', 'hide_code_preprocessor.pyc', 'utils.pyc']
Custom JS contents:
Basically what's happening is the pip installer isn't installing hide_code into your conda environment. Running python -c "import hide_code as hc; hc.install('/home/kaushik/anaconda2/lib/python2.7/site-packages/notebook/static/custom')"
may take care of it.
Thanks! Yes your suggestion now brings back the icons for hide code, export to html and pdf back. But now back to the original problem. Hide code button works. But the export to html and pdf gives Page 404 error. Bummer!
Did you start juypter using jupyter notebook --NotebookApp.server_extensions="['hide_code.hide_code']"
from inside your conda environment?
OK, I did jupyter notebook --NotebookApp.server_extensions="['hide_code.hide_code']"
and I can hide the code fine, but exporting to html generates the html file but the code is visible.
Did you save the workbook before exporting?
Yes, I did save.
Would you post the output from Juypter's console when the 404 error happens?
[W 13:44:32.633 NotebookApp] server_extensions is deprecated, use nbserver_extensions
[I 13:44:33.610 NotebookApp] [nb_conda_kernels] enabled, 2 kernels found
[I 13:44:34.016 NotebookApp] hide_code: Attempting to load hid_code export handler extensions.
[I 13:44:34.018 NotebookApp] hide_code: Hide_code export handler extensions loaded.
[I 13:44:35.114 NotebookApp] [nb_anacondacloud] enabled
[I 13:44:35.119 NotebookApp] [nb_conda] enabled
[I 13:44:35.121 NotebookApp] ✓ nbpresent HTML export ENABLED
[W 13:44:35.121 NotebookApp] ✗ nbpresent PDF export DISABLED: No module named nbbrowserpdf.exporters.pdf
[I 13:44:35.136 NotebookApp] Serving notebooks from local directory: /home/kaushik/notebooks
[I 13:44:35.136 NotebookApp] 0 active kernels
[I 13:44:35.136 NotebookApp] The Jupyter Notebook is running at: http://localhost:8888/?token=cb4ec14051b259c80ce745f2768c364bd9f17b9a39137ea2
[I 13:44:35.136 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 13:44:35.141 NotebookApp]
Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://localhost:8888/?token=cb4ec14051b259c80ce745f2768c364bd9f17b9a39137ea2
[I 13:44:35.837 NotebookApp] Accepting one-time-token-authenticated connection from ::1
[I 13:44:40.865 NotebookApp] Kernel started: 281b062a-ed0f-440a-9e5e-4a9f8769bc96
[I 13:44:43.960 NotebookApp] Saving file at /test.ipynb
[I 13:44:45.335 NotebookApp] hide_code: Starting HTML export for None
[I 13:44:45.532 NotebookApp] hide_code: Finished HTML export for None
any resolution on this yet?
I'm another Anaconda user with the same issues - I followed all the advice here and got the buttons to show up, but no "hide code" selections are being respected with regards to the output.
Same issue as coljac. If I hide code via the cell toolbar or via the buttons on the main toolbar and then diff the output html with the html generated when the code was showing there are no differences. The buttons do function as expected on screen though. It seems to be just a problem with the exported data files (html and both pdf forms).
+1 for the "code gone on screen, but not in output" issue. Python 3.5.1, Jupyter 4.2.1. Added
"hide_code.hide_code": true
to my jupyter_notebook_config.json
to get around the 404 error, but now I get a PDF that's full of code, even though the code disappears in the browser when using the notebook.
@coljac @MikeHigginbottom @npyoung would you post the version of nbconvert you're using?
Also, this extension prints some stuff in Jupyter's console during the export process. Do you see any error messages?
[I 20:22:14.203 NotebookApp] hide_code: Starting HTML export for None
[I 20:22:14.346 NotebookApp] hide_code: Finished HTML export for None
[I 18:35:59.020 NotebookApp] hide_code: Attempting to load hid_code export handler extensions.
[I 18:35:59.024 NotebookApp] hide_code: Hide_code export handler extensions loaded.
No error messages on jupyter notebook start.
jupyter nbconvert --version
4.2.0
4.2.0 with no errors:
[I 08:46:48.596 NotebookApp] hide_code: Starting HTML export for None
[I 08:46:48.896 NotebookApp] hide_code: Finished HTML export for None
That's helpful. Please check the metadata for your notebook. Select "Edit Metadata" as the cell toolbar, pick a cell with the code hidden, then click on the "Edit Metadata" button. Do you see JSON similar to this:
{
"deletable": true,
"collapsed": false,
"editable": true,
"hideCode": true
}
With the code hidden there is no Edit Metadata button showing. With the code showing the JSON is empty.
It doesn't look like you can see the "Edit Metadata" buttons on hidden cells. Unhidden code cells have
{
"trusted": true,
"collapsed": false
}
I also tried hiding the code, saving, and looking at the raw notebook json - no "hideCode" key in the metadata there either.
Good, making some progress. What version of notebook are you running?
jupyter notebook --version
gives 4.3.1
for me
Tested with notebook 4.3.1, and not seeing any issues. Not sure why this is happening. The cell metadata isn't being written for some reason on your setup. Exporting depends on the metadata to render correctly. Are there any error messages in the console?
I'm gonna take a stab in the wild dark then and suggest it might be a path issue (it's always a path issue). Can you give us a rough idea of what is supposed to live where? No errors in the console by the way.
I've got the next version ready on the dev branch. Maybe that will take care of these issues. The dev version uses nbextension installation instead of bootstrapping custom.js and jupyter config files. To install:
pip install git+https://github.com/kirbs-/hide_code.git@dev --upgrade
python -c "import hide_code; hide_code.uninstall_bootstrapped_files()"
jupyter nbextension install --py hide_code
jupyter nbextension enable --py hide_code
jupyter serverextension enable --py hide_code
Note: add --sys-prefix
to jupyter nbextension
to install into virtualenv or conda environment.
Followed those steps (I think step 5 should be serverextension
rather than server_extension
btw). Metadata and buttons are now present for hidden code as you described earlier. Existing notebooks still don't hide code on export. Not sure if that behaviour is expected or not. New notebooks seem to work fine now though. Consider this closed with thanks from my perspective.
Thanks, fixed the typo. Still not sure what caused the first issue. Sounds like either hide_code or notebook JS is corrupting/mangling the cell metadata. When upgrading hide_code, Jupyter and its dependencies is also upgraded to the latest version. Hopefully, that cleans up everything. Anyhow, glad this is resolved.
@kmallick2000 @npyoung @coljac do the instructions above fix your issue too?
I performed the following steps:
--sys-prefix
)At this point, the toolbar was there, and the edit metadata button persists when I hide the code, with hideCode: true
visible when hidden. Positive.
Trying to export gives me a 404:
404 GET /notebooks/aes/test.ipynb/export/html
I'll edit this if I find the solution - I might have missed something obvious.
Everything looks like it's working now.
Sorry, checking in late. I confirm that the solution proposed by coljac is working! Thanks a lot for fixing it and for the excellent extension. The export to pdf still shows the 500 : Internal Server Error, but the Export ot pdf by Latex works for me. I am happy.
Confirming (finally) that the fix works for me, using v0.4.0 now.
Thanks for writing the very useful code. I am using 4.1.36-44 kernel on Leap 42.1. I can get the code to hide within Jupyter, but cannot get the code to hide in the output to html or pdf, either through command prompt or using the buttons. I get the error:
404 : Not Found
You are requesting a page that does not exist!
I tried putting the notebook file in the root directory of Jupyter and that did not help either. I have conda updated, I am using python 2.7 and nbconvert is ver. 4.2.0. Any help will be appreciated.