Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
272 views
in Technique[技术] by (71.8m points)

python - Configuring Jupyter default imports

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

A bit of background:

  • Jupyter provides the UI/environments such as the console and notebook. It defers to what it calls kernels for execution.
  • IPython provides the default (Python) kernel for Jupyter.
  • Jupyter configuration doesn't affect kernels directly, but each kernel may have its own configuration.

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.

  1. Create the default profile, if it doesn't exist already (it probably does):

    ipython profile create
    
  2. 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...