sudo:jupyter:未找到命令&OSError:[Errno 13] 权限被拒绝:'/usr/local/share/jupyter'

sudo:jupyter:未找到命令&OSError:[Errno 13] 权限被拒绝:'/usr/local/share/jupyter'

如果我尝试检查是否jupyter在我的路径中或未被使用,我会得到一些回报。

which jupyter
/home/usr/.local/bin/jupyter

但是当我尝试安装并启用扩展时,出现错误:

sudo jupyter serverextension enable --py ipyparallel
sudo jupyter nbextension install --py ipyparallel
sudo jupyter nbextension enable --py ipyparallel

错误说sudo: jupyter: command not found

而且我需要 sudo 访问权限。因为没有 sudo 执行,无法完成工作:

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: OK

在这种情况下(^),错误提示如下:OSError: [Errno 13] Permission denied: '/usr/local/share/jupyter'

那么我该如何解决这个问题?

export PATH="$HOME/.local/bin:$PATH"在最后一行添加了~/.bashrc

答案1

当您使用 时sudo,将启用不同的环境。因此,您的私有 bin 文件夹 ( /home/usr/.local/bin/jupyter) 不再位于搜索路径中,并且不再能找到该命令。

有效路径在 sudoers 文件中定义。在 Ubuntu 上,它显示为:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin

因此,请在 ( ) 中安装二进制文件,/usr/local/bin以便在通过命令运行时找到它sudo。按照惯例,这是针对手动安装的可执行文件的目录,即由管理员手动管理,而不是由发行版自动管理。

或者,将二进制文件保留在原处并使用命令-E的选项sudo。这样可以保留您当前的环境,包括路径。一些想法:1) 操作系统必须允许这样做(Ubuntu 允许这样做);2) 如果可能的话,最好不要在自己的用户文件夹中执行需要 root 权限的操作;3) 绝对不要以这种方式运行图形程序,因为它可能会弄乱权限。

相关内容