sudo: jupyter: command not found & OSError: [Errno 13] Permission denied: '/usr/local/share/jupyter'
If I try to check if jupyter is in my path or not using, I get something in return.
which jupyter
/home/usr/.local/bin/jupyterBut when I try to install and enable an extension, I face error:
sudo jupyter serverextension enable --py ipyparallel
sudo jupyter nbextension install --py ipyparallel
sudo jupyter nbextension enable --py ipyparallelThe error says sudo: jupyter: command not found
And I need sudo access. Cause executing without sudo, doesn't get the job done:
jupyter serverextension enable --py ipyparallel
jupyter nbextension install --py ipyparallel
jupyter nbextension enable --py ipyparallel
Enabling: ipyparallel.nbextension
- Writing config: /home/usr/.jupyter - Validating... ipyparallel.nbextension OK
Installing /home/usr/.local/lib/python2.7/site-packages/ipyparallel/nbextension/static -> ipyparallel
Traceback (most recent call last): File "/home/usr/.local/bin/jupyter-nbextension", line 8, in <module> sys.exit(main()) File "/home/usr/.local/lib/python2.7/site-packages/jupyter_core/application.py", line 270, in launch_instance return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs) File "/home/usr/.local/lib/python2.7/site-packages/traitlets/config/application.py", line 664, in launch_instance app.start() File "/home/usr/.local/lib/python2.7/site-packages/notebook/nbextensions.py", line 988, in start super(NBExtensionApp, self).start() File "/home/usr/.local/lib/python2.7/site-packages/jupyter_core/application.py", line 259, in start self.subapp.start() File "/home/usr/.local/lib/python2.7/site-packages/notebook/nbextensions.py", line 716, in start self.install_extensions() File "/home/usr/.local/lib/python2.7/site-packages/notebook/nbextensions.py", line 695, in install_extensions **kwargs File "/home/usr/.local/lib/python2.7/site-packages/notebook/nbextensions.py", line 225, in install_nbextension_python destination=dest, logger=logger File "/home/usr/.local/lib/python2.7/site-packages/notebook/nbextensions.py", line 126, in install_nbextension ensure_dir_exists(nbext) File "/home/usr/.local/lib/python2.7/site-packages/jupyter_core/utils/__init__.py", line 13, in ensure_dir_exists os.makedirs(path, mode=mode) File "/usr/lib/python2.7/os.py", line 150, in makedirs makedirs(head, mode) File "/usr/lib/python2.7/os.py", line 157, in makedirs mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/usr/local/share/jupyter'
Enabling tree extension ipyparallel/main... - Validating: OKIn this(^) case, the error says : OSError: [Errno 13] Permission denied: '/usr/local/share/jupyter'
So how can I fix this?
I've added export PATH="$HOME/.local/bin:$PATH" at the last line of ~/.bashrc
1 Answer
When you use sudo, a different environment is in effect. Accordingly, your private bin folder (/home/usr/.local/bin/jupyter) is not anymore in the search path, and the command is not anymore found.
The path that is in effect is defined in the sudoers file. On Ubuntu, it appears as:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/binThus, install your binary in (/usr/local/bin) for it to be found when running it through the sudo command. By convention, that is the directory aimed for manually installed executables, i.e., manually managed by the administrator rather than automatically by the distribution.
Alternatively, keep the binary where it is and use the -E option of the sudo command. That preserves your current environment, including the path. Some thoughts: 1) the operating system must allow that (Ubuntu does), 2) if possible, it is better practice to stay out of your own user folder for operations requiring root permissions and 3) certainly do not run graphic programs this way because it may mess up permissions.