To create a new profile:
!ipython profile create pycones14
This creates a profile in your IPYTHONDIR (ipython locate
is a quick way to see where your IPYTHONDIR is), and populates it with automatically generated default config files.
profile_path = !ipython locate profile pycones14
profile_path = profile_path[0]
profile_path
ls -lh $profile_path
In the startup folder of your new profile you should have a README file with the following content:
This is the IPython startup directory
*.py* and *.ipy* files in this directory will be run *prior* to any code or files specified via the exec_lines or exec_files configurables whenever you load this profile.
Files will be run in lexicographical order, so you can control the execution order of files with a prefix, e.g.:
00-first.py 50-middle.py 99-last.ipy
This files are executed at the beginning when the profile is used. You can use python (*.py) or ipython (*.ipy) scripts. For example, most of the times I do the following in the first code cell of the notebooks:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
This is not valid python code but it is valid ipython code so you can do the following.
You can find the following paragraph in the official docs summarising the text above:
%%writefile $profile_path/startup/01-startimports.ipy
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
[TIP] If you want valid python scripts you can use the IPython magics as follows:
from IPython import get_ipython ipython = get_ipython() ipython.magic("timeit for i in range(10000):pass")
This way you don't have to use ***.ipy*** scripts and you have valid python scripts. In the previous case we could do:
%%writefile $profile_path/startup/01-startimports.py import numpy as np import pandas as pd import matplotlib.pyplot as plt from IPython import get_ipython ipython = get_ipython() ipython.magic("matplotlib inline")
Now, we can start with our new profile and all the included files will be executed:
ipython notebook --profile pycones14
In the root of your new profile dir you could find the following files:
The official docs could be found in this link.
Let's show the config file for the notebook.
%load $profile_path/ipython_notebook_config.py