workaround for missing --script in ipython notebook 3.0.0-dev - jupyter-notebook

I've been using automaticall saved scripts beside .ipynb files as a convenient way to write modules using ipython notebook. I updated to the head version today, and it seems the --script functionality has been removed.
Is there a way to obtain that functionality (automatically on save) with the latest ipython?
Running ipython notebook gives me a message telling me that it's been removed, and suggests doing
ipython nbconvert --to python [notebook]
To make that work automaticaly, I'd have to trigger it on each save - is there an easy way to achieve that?

Not really a workaround, but the --script functionality was still present in release 2.3.0 (if you're running from a live git repo, you can checkout tag 'rel-2.3.0').

Related

WebIO is not being detected by Jupyter Notebook

I am trying to open a Jupyter Notebook file in classic Jupyter Notebook interface. I am attempting to create an interective app that uses Julia programming language in interactive codes. For that I am trying to use the Interact library, because I know it features things such as buttons, sliders, etc. It requires the WebIo extension to be installed. However, from what I have experienced so far, Jupyter notebook does not detect the WebIO extension.
I tried following the instructions at https://juliagizmos.github.io/WebIO.jl/stable/gettingstarted/ and at https://juliagizmos.github.io/WebIO.jl/stable/troubleshooting/not-detected/. In the last link I found that another extension needed to be install and I found more information in this link (https://juliagizmos.github.io/WebIO.jl/latest/providers/ijulia/). I tried executing this command in my Windows prompt and it had apperently been succesful. When executing the command suggested at the second link, I got an error in the Julia REPL saying that WebIO extension for Jupyter Lab must be installed through Python or Conda, which I had already done.
I am also a bit confused as to how I can check to see if the extension is enabled.
I believe the problem has to do either with the installation of IJulia or the pip installation of WebIO. I rarely use pip, so I don't know if I did it correctly.
Thank you.

How to have the autocomplete feature in jupyter notebook like we have in pycharm or visual code?

I just want that autocomplete feature like I have in VC studio and pycharm in jupyter notebook, is there any way folks? I saw in some youtube tutorials people completing the code using the tool, any idea about that?
There is a hinterland functionality that when enabled then auto-complete code works.
For you to access the functionality first install jupyter_contrib_nbextensions as follows:
Install the python package
pip install jupyter_contrib_nbextensions
Then install javascript and css files
jupyter contrib nbextension install --user
More information on how to install can be found here
Then re-start the jupyter notebook. Look for a tab named Nbextensions and click on it. Then look for Hinterland and make sure that it is checkd:
Refresh/Restart jupyter notebook for changes to take place.
You just have to click the "Tab"-Button after typing something (e.g. a Class name followed by a dot). Then you find suggestions that you can insert by using Tab or Enter.

What happened to the TOC extension for ipython notebook?

I'm trying to install the great table of contents extension in a new computer. but I cant find it anymore. the only page I do find does not explain how to install the extension on windows.
So.. How can I install it, and why is it not a part of the official Ipython notebook? I simply can't understand how people are getting along without it.
I've installed toc nbextension successfully with Jupyter 4 (ie. ipython notebook 4) recently.
In fact installing extension is easier than before :)
I post my solution here, may it help.
## download
mkdir toc
cd toc
wget https://raw.githubusercontent.com/minrk/ipython_extensions/master/nbextensions/toc.js
wget https://raw.githubusercontent.com/minrk/ipython_extensions/master/nbextensions/toc.css
## install and enable
cd ..
jupyter-nbextension install --user toc
jupyter-nbextension enable toc/toc
A bit more explain:
install will copy toc to ~/.local/share/jupyter/nbextensions/
enable will modify ~/.jupyter/nbconfig/notebook.json.
You can check these two place to see what happened.
Note: we use enable toc/toc here is because toc.js is in ~/.local/share/jupyter/nbextensions/toc/.
If you put toc.js and toc.css directly in ~/.local/share/jupyter/nbextensions/ then you should use enable toc here.
Edit
Sorry, I didn't notice the orginal problem is on windows. I'm not sure if it's same for windows jupyter, any report is welcome.
Update
Now the toc nbextension has been added into this project which provide a collection of kinds of nbextensions. It's very easy to install and manage, worth to try!
I cannot tell you specific Windows advice, but think the key points should be platform independent:
Create a profile (either a default profile or a named one - you'll probably want default to start).
Locate where the profile is.
Add the custom.js file into the profile.
Edit the custom.js file to point to the notebook extension code.
In a bit more detail, setting up a profile is covered in detail here but for a default profile just go to the command line and enter
ipython profile
Next, locate where your profile is stored by typing at the command line
ipython locate
Call that <profile_dir>.
The rest follows the (Windows equivalent of!) the instructions on the link you have: underneath <profile_dir> navigate to (creating any directories that do not already exist)
<profile_dir>/static/custom/
and add the custom.js file as shown. Then edit the first line, where it has "nbextensions/toc" to point to the location where you have placed the toc.js file you have downloaded. This location is relative to the <profile_dir>; for me I have
<profile_dir>/static/custom/custom.js
<profile_dir>/static/custom/nbextensions/toc.js
<profile_dir>/static/custom/nbextensions/toc.css
and the first line of custom.js reads
require(["/static/custom/nbextensions/toc.js"], function (toc) {
Finally, note that this is with version 1.1.0 of the notebook - if you're using an earlier version I strongly suggest you upgrade before trying this.
You'll also find the official installation instructions at:
https://github.com/minrk/ipython_extensions
These instructions include curl commands for retrieving the toc.js and toc.css files from GitHub, which worked fine for me in a bash shell on linux Mint.
For Windows 7, I used a Git Shell (see http://msysgit.github.io/) to execute the curl commands
This IPython Notebook semi-automatically generates the files for minrk's table of contents in Windows. It does not use the 'curl'-commands or links, but writes the *.js and *.css files directly into your IPython Notebook-profile-directory.
There is a section in the notebook called 'What you need to do' - follow it and have a nice floating table of contents : )
Here is an html version which already shows it:
http://htmlpreview.github.io/?https://github.com/ahambi/140824-TOC/blob/master/A%20floating%20table%20of%20contents.htm

Save ipython notebook as script programmatically

The excellent ipython notebook has a handy --script command line flag that automatically saves a copy of the notebook as a .py script file (removing any header and markdown cells). Is there a way to switch this feature on from inside the notebook itself after the notebook is opened? Apparently, this option is not accessible to the %config magic.
Is there a way to have a cell that does this conversion? Is there any command-line tool I could use to do the conversion, and just have that in a shell command run from the notebook? (It seems that nbconvert does not output to .py.)
The reason I ask is that I have a git repository of notebooks, and I need to make sure the .py files are kept up to date when users change the notebooks themselves because the .py files are used to create c++ code from the contents of the notebooks. But I can't rely on users to set the --script flag because they'll always forget. (And I include myself in that group of users.)
Better yet (at least for my purposes): ipython respects local copies of the ipython_notebook_config.py file. So I can just add
c = get_config()
c.NotebookManager.save_script = True
to such a file in my notebook directory. Apparently, ipython first reads ~/.ipython/profile_default/ipython_notebook_config.py, and then reads the local copy of that file. So it's safe to use without worrying about demolishing the user settings.
This was not at all clear to me from the documentation, but I just tried it and it worked.
Oh. My mistake. nbconvert can handle conversions to script. So I can do something like this:
!ipython nbconvert --to python MyNB.ipynb
Of course, this line will get saved to the script, which means the script will try to re-save the notebook to itself every time it's executed. That's a bit circular, and I can imagine it could cause problems with some of my more outlandish hacks. Instead, we can ensure that it's only run from ipython by wrapping it as follows:
try :
if(__IPYTHON__) :
!ipython nbconvert --to python MyNB.ipynb
except NameError :
pass
Note that the conversion process will automatically convert the ! syntax to something that is acceptable to plain python. This is apparently not the case with the --script conversion. So the extra-safe way to do this is
try :
if(__IPYTHON__) :
get_ipython().system(u'ipython nbconvert --to python MyNB.ipynb')
except NameError :
pass

Can I use variables on an IPython notebook markup cell?

I have an IPython notebook and I would like to use one of my variables inside a markup cell. Is this even possible? If so, how do you do it?
If you don't mind a code cell that does the job, there is a possibility without adding any extensions.
from IPython.display import Markdown as md
fr=2 #GHz
md("$f_r = %i$ GHz"%(fr))
This will show a markdown cell in a nicely LaTeX formatted output
Currently, this is not possible, however there is a large discussion on this topic here https://github.com/ipython/ipython/pull/2592. The PR is currently closed, but a corresponding issue is opened https://github.com/ipython/ipython/issues/2958 and marked as wishlist.
Update
In the meantime an IPython extension has appeared which allows to render python variables in markdown cells. This extension is part of the IPython notebook extensions and works with IPython 2.x and 3.x. For a detailed description see the wiki page.
It is not officially supported, but installing the python markdown extension will allow you to do so. It is part of the nbextensions, for which you will find installation instructions on their github page. Make sure you'll enable the python markdown extension using a jupyter command or the extension configurator.
Calling python variables then should work with the {{var-name}} syntax, which is described in the readme of the corresponding github page (linked in the wiki):
For example: If you set variable a in Python
a = 1.23
and write the following line in a markdown cell:
a is {{a}}
It will be displayed as:
a is 1.23
Further info on this functionality being integrated into ipython/jupyter is discussed in the issue trackers for ipython and jupyter.
The link: installing notebook extention
gives a clear description of what is necessary to enable the use of variables in markdown cells. Following it, performed the following actions to realize it:
conda install -c conda-forge jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
after a successful completion of the above command I enabled the python markup extension, from jupyter dashboard, as per the following illustration:
Last but not least!!! The NOTEBOOK HAS TO BE TRUSTED to make the markup extension works with python variables
and it worked for me!

Resources