Hello,
I installed the jupyter notebook on macOS using the pip with the following command:
pip3 install jupyter
After installing it successfully, I encounter the following error when I try to executejupyter notebook from command line:
Traceback (most recent call last):
File "/usr/local/bin/jupyter-notebook", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python3.7/site-packages/jupyter_core/application.py", line 266, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "/usr/local/lib/python3.7/site-packages/traitlets/config/application.py", line 658, in launch_instance
app.start()
File "/usr/local/lib/python3.7/site-packages/notebook/notebookapp.py", line 1631, in start
browser = webbrowser.get(self.browser or None)
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/webbrowser.py", line 42, in get
register_standard_browsers()
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/webbrowser.py", line 531, in register_standard_browsers
raw_result = subprocess.check_output(cmd, stderr=subprocess.DEVNULL)
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 376, in check_output
**kwargs).stdout
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 453, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 756, in __init__
restore_signals, start_new_session)
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1499, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: 'xdg-settings'
It seems that the error was caused by the permission problem with 'xdg-settings'. I checked that Google Chrome is my default browser. I tried the following command by changing the c.NotebookApp.allow_root to True in the jupyter_notebook_config.py file, and it can successfully open jupyter notebook in the browser Safari:
sudo jupyter notebook
I also have tried to set c.NotebookApp.browser = u'/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome %s'. I encounter the same error with jupyter notebook but can successfully open it with sudo jupyter notebook in the Google Chrome.
Do you have an idea of how to solve the Permission denied: 'xdg-settings' problem? Has anyone encountered a similar problem before? Thanks.
Hello,
If you don't mind opening your browser manually, you can pass --no-browser when starting the notebook: $ jupyter notebook --no-browser. You can then navigate to the notebook in a browser manually and do you your work.
I am getting the same error after installing python 3.7 using anaconda on macOS.
@warp-x thanks for the advice. I can start the notebook using --no-browser as described above.
It's a if/else logic bug in webbrowser.py; a simple fix is to edit /usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/webbrowser.py (or wherever Jupyter is pointing you to) and then look for xdg-settings in the code.
Several lines above (15 in my case), you will have if sys.platform[:3] == "win": if you change it to elif sys.platform[:3] == "win": then the Darwin/Windows/Linux will work properly. I'm running python3.7 from Homebrew using macOS 10.14.2.
Great, thx!
I originally fixed this using rrios-eq's solution, but I got it again after I updated and the same solution no longer worked. I added an except in the else block after if sys.platform[:3] == "win":. My webbrowser.py statement now has this chunk of code, and it works.
if sys.platform[:3] == "win":
# First try to use the default Windows browser
register("windows-default", WindowsDefault)
# Detect some common Windows browsers, fallback to IE
iexplore = os.path.join(os.environ.get("PROGRAMFILES", "C:\\Program Files"),
"Internet Explorer\\IEXPLORE.EXE")
for browser in ("firefox", "firebird", "seamonkey", "mozilla",
"netscape", "opera", iexplore):
if shutil.which(browser):
register(browser, None, BackgroundBrowser(browser))
else:
# Prefer X browsers if present
if os.environ.get("DISPLAY"):
try:
cmd = "xdg-settings get default-web-browser".split()
raw_result = subprocess.check_output(cmd, stderr=subprocess.DEVNULL)
result = raw_result.decode().strip()
except (FileNotFoundError, subprocess.CalledProcessError):
pass
except (NotADirectoryError, subprocess.CalledProcessError):
pass
else:
global _os_preferred_browser
_os_preferred_browser = result
register_X_browsers()
The only thing I added was:
except (NotADirectoryError, subprocess.CalledProcessError):
pass
It's a if/else logic bug in
webbrowser.py; a simple fix is to edit/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/webbrowser.py(or wherever Jupyter is pointing you to) and then look forxdg-settingsin the code.Several lines above (15 in my case), you will have
if sys.platform[:3] == "win":if you change it toelif sys.platform[:3] == "win":then the Darwin/Windows/Linux will work properly. I'm running python3.7 from Homebrew using macOS 10.14.2.
This works but need to do this every time I update. Bookmarking this page until there's a permanent solution.
Could someone print more details about the Not a directory error?
It doesn鈥檛 make sense to see that error; xdg-open is a program so it should be a file and executable, it鈥檚 strange that something is trying to open it as a directory.
(And then the real issue is why webbrowser is going into that if branch at all! xdg-open is not on mac)
@heathjohn62,thanks a lot. It worked well on my MAC(macOS 10.15.6).
if sys.platform[:3] == "win":if you change it toelif sys.platform[:3] == "win":then the Darwin/Windows/Linux will work properly. I'm running python3.7 from Homebrew using macOS 10.14.2.
I ran into this problem while running on Jupyter labs. I tried the above suggestion, but had errors due to the different library script. Instead, mine worked when changing if sys.platform[:3] == "darwin": to elif sys.platform[:3] == "darwin":. I'm running python3.7 from Homebrew using macOS Catalina 10.15.7.
Most helpful comment
It's a if/else logic bug in
webbrowser.py; a simple fix is to edit/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/webbrowser.py(or wherever Jupyter is pointing you to) and then look forxdg-settingsin the code.Several lines above (15 in my case), you will have
if sys.platform[:3] == "win":if you change it toelif sys.platform[:3] == "win":then the Darwin/Windows/Linux will work properly. I'm running python3.7 from Homebrew using macOS 10.14.2.