How do I tell Jupyter (console and notebook) to import some Python packages by default? I would like to do this using only the .jupyter
folder
I personally couldn't find a way to do so only using the .jupyter
folder. You have to specify the commands to be executed on startup in the .ipython
folder anyway:
~/.ipython/profile_default/ipython_config.py
if it not existsAdd something like this:
c = get_config() c.InteractiveShellApp.exec_lines = [ 'import numpy as np\n' 'import scipy as sp\n' 'import matplotlib as plt\n' ]
You can also specify any valid commands here, not only imports.
A bit of background:
The IPython configuration resides in your .ipython
directory. The quickest way to add code to run on startup of IPython (affects IPython sessions in the terminal and notebook) is to add startup files to your IPython profile.
Create the default profile, if it doesn't exist already (it probably does):
ipython profile create
Make a Python script ~/.ipython/profile_default/startup/whateveryouwant.py
and add any imports or other commands in there that you would like to have ready whenever you start IPython. IPython will run this script and any others in that directory every time it starts up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With