Solve the problem that Jupyter Notebook cannot automatically open the browser

question:

When starting Jupyter Notebook from the command line, the browser does not pop up automatically.

Solution

method 1

Copy the URL below directly into the address bar of your browser.

Or enter the URL in the browser address bar: http://localhost:8888/tree

This can also open Jupyter, but it is too troublesome to manually enter each time, so it is not recommended.

Method 2

1. Press the win+r key, then enter cmd, and press Enter to open the command window.

2. Enter the following command on the command line:

jupyter notebook --generate-config

 If prompted, type y and press Enter.

 3. According to the path obtained above, find the jupyter_notebook_config.py file in the resource manager.

Open with Notepad or Notepad++:

 4. Press Ctrl+F to search, and enter the following content in the search target:

c.NotebookApp.password =

 Find where the target is located:

 5. Add the code below the target. This code specifies the browser that jupyter will automatically open. You can choose the browser (Google, edge, etc.) according to your preferences.

Below is the code using Google Chrome :

import webbrowser
webbrowser.register('chrome', None, webbrowser.GenericBrowser(r'C:\Program Files(x86)\Google\Chrome\Application\chrome.exe'))
c.NotebookApp.browser = 'chrome'

Note: C:\Program Files(x86)\Google\Chrome\Application\chrome.exe is the installation location of Google Chrome in your own computer. If your Google Chrome is not in this location, you need to change it to your own installation location .

You can determine where your browser is installed by doing the following:

Right-click Google Chrome, click Properties, and the target is the installation location of your browser.

 As shown in the picture above, my browser is located in my user directory, so I need to replace the path of the above code with this path, and start Jupyter after saving.

If there is Chinese in your path, you may still not be able to automatically open the browser when you start, and the following error will be reported:

This is a decoding error, which is caused by Chinese characters in the path. To solve this problem, you can change the Chinese in the path to English, but since the Chinese here is my computer user name, I dare not change it at will (I will cry if I say too much, and I often suffer from this Chinese name problem). Another method is to use a text editor such as Notepad++ to save the jupyter_notebook_config.py file as a py script encoded in UTF-8, replacing the original file encoded in ANSI.

If it doesn't work, I use other browsers that don't have Chinese in the path. I finally chose to use the edge browser.

 Below is the code to use the edge browser

import webbrowser
webbrowser.register('Microsoft Edge', None, webbrowser.GenericBrowser(r'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe'))
c.NotebookApp.browser = 'Microsoft Edge'

Note: C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe is the installation location of the edge browser on your own computer. If your edge browser is not in this location, you need to change it to your own installation location . You can confirm your installation location by the method mentioned above.

 After saving, restart Jupyter Notebook, then you will find that Jupyter Notebook can automatically open the browser

Guess you like

Origin blog.csdn.net/lyb06/article/details/130498101