In ipython, I have the ipython_config.py
when I make changes in this file, how I can reload ipython ? (without restart ipython)
for example for change the prompt.
As far as I know, you can't - that file is read when you start IPython. You can change any configured value while IPython is running:
%config PromptManager.in_template = "\\#>>>"
That won't be stored in the config file, though.
Related
The iPython profile or Jupyter profile path: ~/.ipython/profile_default/startup/startup.ipy
I update this quite often.
Is there a way to source this within a notebook like when you're in the terminal and source ~/.bash_profile after you make an update? My current method is to close the kernel and Jupyter session then restart.
You can use %run to do this:
%run ~/.ipython/profile_default/startup/startup.ipy
If you do %run -i [script], then your current interactive namespace will be available to the script.
So I've installed Homestead and Laravel going through the steps in Laravel Documentation.
One problem that occured throughout the process, is that I can't set "homestead" command, to be accessible globally.
The Documentation writes, that I should just paste that line into the temrinal:
alias homestead='function __homestead() { (cd ~/Homestead && vagrant $*); unset -f __homestead; }; __homestead'
But that only makes it accessible globally untill I restart my terminal.
I've also edited my bash_profile file, adding
export PATH="/Users/MacbookPro/.composer/vendor/bin:$PATH"
to the very bottom of the file, but that does not work either.
To make your alias works every time you open terminal, you've to put your alias into .bashrc file so it been executed every time you open a new terminal tab.
Just add youralias to ~/.bashrc file
or
If you're using ohmyz.sh add youralias to ~/.zshrc file instead.
Is there a way to open a new Jupyter notebook from a template? (which would not itself be modified)
I would expect something like this perhaps:
jupyter --template <template-filename>
(re-using the existing jupyter-notebook server session if there is one already)
But I don't seem to see how to do it (as of Jupyter 4.0.6)
I admit it's a rather hacky workaround, but just in case there is no implemented solution: You could make an alias in your .bashrc like this:
alias newnb='cp -i ~/templates/jupyter.ipynb new_notebook.ipynb && juypter notebook'
Then, the command newnb in your terminal copies the template file to your current directory and invokes the jupyter notebook session on this directory, where you could open new_notebook.ipynb with the given content.
ipython notebook has setting for default working directory
c.FileNotebookManager.notebook_dir = '/path/to/my/desired/dir'
is there analogous setting for ipython console (terminal) ? I have tried adjusting following configuration parameter:
c.TerminalInteractiveShell.ipython_dir = '/path/to/my/desired/dir'
but this seems to have no effect. There is also no comment as to what this parameter is supposed to effect.
How can I configure ipython so that my working directory upon start will be /path/to/my/desired/dir, irrespective from where I started ipython ?
From your home directory, go to .ipython, then your profile directory (probably profile_default), then startup. In there, create a new file with the extension .ipy, containing the lines:
import os
os.chdir('/path/to/my/desired/dir')
As pointed out by crowie in the comments, the .ipy extension also enables you to use IPython "magic" commands, so you could instead say:
%cd /path/to/my/desired/dir
Does anyone know if it is possible to run an IPython/Jupyter notebook non-interactively from the command line and have the resulting .ipynb file saved with the results of the run. If it isn't already possible, how hard would it be to implement with phantomJS, something to turn the kernel on and off, and something to turn the web server on and off?
To be more specific, let's assume I already have a notebook original.ipynb and I want to rerun all cells in that notebook and save the results in a new notebook new.ipynb, but do this with one single command on the command line without requiring interaction either in the browser or to close the kernel or web server, and assuming no kernel or web server is already running.
example command:
$ ipython notebook run original.ipynb --output=new.ipynb
Yes it is possible, and easy, it will (mostly) be in IPython core for 2.0, I would suggest looking at those examples for now.
[edit]
$ jupyter nbconvert --to notebook --execute original.ipynb --output=new.ipynb
It is now in Jupyter NbConvert. NbConvert comes with a bunch of Preprocessors that are disabled by default, two of them (ClearOutputPreprocessor and ExecutePreprocessor) are of interest. You can either enabled them in your (local|global) config file(s) via c.<PreprocessorName>.enabled=True (Uppercase that's python), or on the command line with --ExecutePreprocessor.enabled=True keep the rest of the command as usual.
The --ExecutePreprocessor.enabled=True has convenient --execute alias that can be used on recent version of NbConvert. It can be combine with --inplace if desired
For example, convert to html after running the notebook headless :
$ jupyter nbconvert --to=html --execute RunMe.ipynb
converting to PDF after stripping outputs
$ ipython nbconvert --to=pdf --ClearOutputPreprocessor.enabled=True RunMe.ipynb
This (of course) does work with non-python kernels by spawning a <insert-your-language-here> kernel, if you set --profile=<your fav profile>. The conversion can be really long as it needs to rerun the notebook. You can do notebook to notebook conversion with the --to=notebook option.
There are various other options (timeout, allow errors, ...) that might need to be set/unset depending on use case. See documentation and of course jupyter nbconvert --help, --help-all, or nbconvert online documentation for more information.
Until this functionality becomes part of the core, I put together a little command-line app that does just what you want. It's called runipy and you can install it with pip install runipy. The source and readme are on github.
Run and replace original .ipynb file:
jupyter nbconvert --ExecutePreprocessor.timeout=-1 --to notebook --inplace --execute original.ipynb
To cover some features such as parallel workers, input parameters, e-mail sending or S3 input/output... you can install jupyter-runner
pip install jupyter-runner
Readme on github: https://github.com/omar-masmoudi/jupyter-runner
One more way is to use papermill, it has Command Line Interface
Usage example: (you need to specify output path for execution results to be stored)
papermill your_notebook.ipynb logs/yourlog.out.ipynb
You also can specify required params if you wish with -p flag for each param:
papermill your_notebook.ipynb logs/yourlog.out.ipynb -p env "prod" -p tests "e2e"
one more related to papermill reply - https://stackoverflow.com/a/55458141/2957102
You can just run the iPython-Notebook-server via command line:
ipython notebook --pylab inline
This will start the server in non-interactive mode and all output is printed below the code. You can then save the .ipynb-File which includes Code & Output.