如何在Jupyter Notebook启动时默认开启%xmode Verbose模式?
I totally get why you ran into that syntax error—jupyter_notebook_config.py is a standard Python configuration file, and IPython magic commands (like %xmode) aren't valid Python syntax there, which is why your import statements worked but the magic command didn't. The good news is you're on the right track thinking about IPython's config; here's how to set this up properly:
Step 1: Generate an IPython profile (if you don't have one)
Open your terminal and run this command to create a default IPython profile (it only needs to be done once):
ipython profile create
This will create a .ipython/profile_default folder in your user directory, which includes the ipython_config.py file we need.
Step 2: Modify the IPython configuration file
Navigate to the .ipython/profile_default folder and open ipython_config.py in your favorite text editor. Look for the line that starts with c.InteractiveShellApp.exec_lines—it might be commented out with a # at the start.
Uncomment that line, then add %xmode Verbose to the list of commands. It should look something like this:
c.InteractiveShellApp.exec_lines = [ '%xmode Verbose' ]
If there are already other commands in that list, just add your %xmode line to the end of the list (make sure to keep the commas formatted correctly!).
Step 3: Restart Jupyter Notebook
Save the changes to ipython_config.py, then close and reopen your Jupyter Notebook session. Now every notebook you launch will automatically have Verbose error mode enabled—no need to run the magic command manually each time!
The reason this works is because Jupyter Notebook uses the IPython kernel under the hood, so any configuration set in IPython's profile applies directly to your notebook sessions.
内容的提问来源于stack exchange,提问作者Blaszard

