使用 pip 卸载 jupyter

使用 pip 卸载 jupyter

jupyter这里有可执行文件:/usr/local/bin/jupyter

我知道我以前一直在使用 Ubuntu 发行版中的 Python 2(没有 Anaconda),所以我认为它jupyter来自系统pip2安装,但我找不到方法来证明这一点,有吗?

假设前面的情况,我已经完成了这两项操作:sudo /usr/local/bin/pip2 uninstall jupyter和这sudo /usr/local/bin/pip2 uninstall notebook(即使在中/usr/local/bin,我仍然需要,sudo因为出于某种原因,似乎其中的所有文件都属于root),但我一直看到这里的可执行文件:/usr/local/bin/jupyter

另外:我知道那jupyter是受影响的,因为现在命令:jupyter notebook给出了这个输出Error executing Jupyter command 'notebook': [Errno 2] No such file or directory

我该如何卸载它?为什么pip2无法删除该可执行文件?

编辑:

我目前在我的文件系统上看到这个:

ls -lah /usr/local/bin | grep jupyter
-rwxr-xr-x  1 root root  222 May  6  2017 jupyter
-rwxr-xr-x  1 root root  221 May  6  2017 jupyter-console
-rwxr-xr-x  1 root root  264 May  6  2017 jupyter-kernelspec
-rwxr-xr-x  1 root root  222 May  6  2017 jupyter-migrate
-rwxr-xr-x  1 root root  224 May  6  2017 jupyter-nbconvert
-rwxr-xr-x  1 root root  224 May  6  2017 jupyter-qtconsole
-rwxr-xr-x  1 root root  243 May  6  2017 jupyter-run
-rwxr-xr-x  1 root root  227 May  6  2017 jupyter-troubleshoot
-rwxr-xr-x  1 root root  255 May  6  2017 jupyter-trust

卸载时jupyter我看到了这一点:

sudo pip2 uninstall jupyter
[sudo] password for <MY_USERNAME>: 
The directory '/home/<MY_USERNAME>/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Uninstalling jupyter-1.0.0:
  /usr/local/lib/python2.7/dist-packages/jupyter-1.0.0.dist-info/DESCRIPTION.rst
  /usr/local/lib/python2.7/dist-packages/jupyter-1.0.0.dist-info/INSTALLER
  /usr/local/lib/python2.7/dist-packages/jupyter-1.0.0.dist-info/METADATA
  /usr/local/lib/python2.7/dist-packages/jupyter-1.0.0.dist-info/RECORD
  /usr/local/lib/python2.7/dist-packages/jupyter-1.0.0.dist-info/WHEEL
  /usr/local/lib/python2.7/dist-packages/jupyter-1.0.0.dist-info/metadata.json
  /usr/local/lib/python2.7/dist-packages/jupyter-1.0.0.dist-info/pbr.json
  /usr/local/lib/python2.7/dist-packages/jupyter-1.0.0.dist-info/top_level.txt
  /usr/local/lib/python2.7/dist-packages/jupyter.py
  /usr/local/lib/python2.7/dist-packages/jupyter.pyc
Proceed (y/n)? y
  Successfully uninstalled jupyter-1.0.0
The directory '/home/<MY_USERNAME>/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

卸载时notebook我看到了这一点:

sudo pip2 uninstall notebook
The directory '/home/<MY_USERNAME>/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Uninstalling notebook-5.0.0:
  /usr/local/bin/jupyter-bundlerextension
  /usr/local/bin/jupyter-nbextension
  /usr/local/bin/jupyter-notebook
  /usr/local/bin/jupyter-serverextension
  /usr/local/lib/python2.7/dist-packages/notebook-5.0.0.dist-info/DESCRIPTION.rst

  [...]

  /usr/local/lib/python2.7/dist-packages/notebook/tree/tests/__init__.pyc
  /usr/local/lib/python2.7/dist-packages/notebook/tree/tests/test_tree_handler.py
  /usr/local/lib/python2.7/dist-packages/notebook/tree/tests/test_tree_handler.pyc
  /usr/local/lib/python2.7/dist-packages/notebook/utils.py
  /usr/local/lib/python2.7/dist-packages/notebook/utils.pyc
  /usr/local/lib/python2.7/dist-packages/notebook/view/__init__.py
  /usr/local/lib/python2.7/dist-packages/notebook/view/__init__.pyc
  /usr/local/lib/python2.7/dist-packages/notebook/view/handlers.py
  /usr/local/lib/python2.7/dist-packages/notebook/view/handlers.pyc
Proceed (y/n)? y
  Successfully uninstalled notebook-5.0.0
The directory '/home/<MY_USERNAME>/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

答案1

我已经使用以下代码行卸载了 jupyter,因此尝试一下。

$ sudo -H python3 -m pip uninstall jupyter_core jupyter_qtconsole nbformat nbconvert notebook

Uninstalling jupyter-core-4.4.0:
      Would remove:
        /usr/bin/jupyter
        /usr/bin/jupyter-migrate
        /usr/bin/jupyter-troubleshoot
        /usr/lib/python3/dist-packages/jupyter.py
        /usr/lib/python3/dist-packages/jupyter_core
        /usr/lib/python3/dist-packages/jupyter_core-4.4.0.egg-info
Uninstalling nbformat-4.4.0:
      Would remove:
        /home/varun/.local/bin/jupyter-trust
        /home/varun/.local/lib/python3.6/site-packages/nbformat-4.4.0.dist-info/*
        /home/varun/.local/lib/python3.6/site-packages/nbformat/*
    Proceed (y/n)? y
      Successfully uninstalled nbformat-4.4.0
Uninstalling nbconvert-5.3.1:
      Would remove:
        /home/varun/.local/bin/jupyter-nbconvert
        /home/varun/.local/lib/python3.6/site-packages/nbconvert-5.3.1.dist-info/*
        /home/varun/.local/lib/python3.6/site-packages/nbconvert/*
    Proceed (y/n)? y
        Successfully uninstalled nbconvert-5.3.1
 Uninstalling notebook-5.6.0:
      Would remove:
        /home/varun/.local/bin/jupyter-bundlerextension
        /home/varun/.local/bin/jupyter-nbextension
        /home/varun/.local/bin/jupyter-notebook
        /home/varun/.local/bin/jupyter-serverextension
        /home/varun/.local/lib/python3.6/site-packages/notebook-5.6.0.dist-info/*
        /home/varun/.local/lib/python3.6/site-packages/notebook/*
    Proceed (y/n)? y
      Successfully uninstalled notebook-5.6.0

答案2

我尝试重现您的情况,但我没有安装 jupyter。因此首先:

sudo pip2 install jupyter

它下载了 jupyter 以及相当多的其他软件包,但首先出现一些错误,然后在重新运行时重复出现:

x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c _scandir.c -o build/temp.linux-x86_64-2.7/_scandir.o
    _scandir.c:14:20: fatal error: Python.h: No such file or directory
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

尽管如此,至少 jupyter 可执行文件似乎已经安装好了:

$ jupyter
usage: jupyter [-h] [--version] [--config-dir] [--data-dir] [--runtime-dir]
               [--paths] [--json]
               [subcommand]
jupyter: error: one of the arguments --version subcommand --config-dir --data-dir --runtime-dir --paths is required

$ whereis jupyter
jupyter: /usr/local/bin/jupyter

但是当我尝试卸载它时:

sudo -H pip2 uninstall jupyter
Skipping jupyter as it is not installed.

如果您在卸载时遇到同样的问题,那么问题可能是 jupyter 一开始就没有正确安装。

但是,我最终能够通过安装 Python dev headers: 正确安装它sudo apt install python-dev。是的,sudo pip2 uninstall jupyter执行成功,但/usr/local/bin/jupyter之后我仍然可以运行。

卸载jupyter-console包(通过找到pip-autoremove -L)也没有起到作用,尽管从名字上看人们可能认为它应该起作用。

但后来我尝试用一​​种古老的“诺顿指挥官”方法来检查里面有什么/usr/local/bin/jupyter。幸运的是,这只是一段简单的 Python 代码,我注意到第 7 行有一个有趣的包引用:

from jupyter_core.command import main

然后就完成了!

$ jupyter
usage: jupyter [-h] [--version] [--config-dir] [--data-dir] [--runtime-dir]
               [--paths] [--json]
               [subcommand]
jupyter: error: one of the arguments --version subcommand --config-dir --data-dir --runtime-dir --paths is required
$ sudo -H pip2 uninstall jupyter-core
Uninstalling jupyter-core-4.4.0:
  Would remove:
    /usr/local/bin/jupyter
    /usr/local/bin/jupyter-migrate
    /usr/local/bin/jupyter-troubleshoot
    /usr/local/lib/python2.7/dist-packages/jupyter.py
    /usr/local/lib/python2.7/dist-packages/jupyter_core-4.4.0.dist-info/*
    /usr/local/lib/python2.7/dist-packages/jupyter_core/*
Proceed (y/n)? y
  Successfully uninstalled jupyter-core-4.4.0
$ jupyter
bash: /usr/local/bin/jupyter: No such file or directory

因此,整个问题在于pip没有删除uninstall它在期间自动下载的依赖项install

更新:关于您在卸载 jupiter / notebook 时遇到的消息 - 我没有收到任何消息,但它们似乎与讨论的问题无关:

目录“/home//.cache/pip/http”或其父目录不属于当前用户,并且缓存已被禁用。请检查该目录的权限和所有者。如果使用 sudo 执行 pip,您可能需要 sudo 的 -H 标志。

如果我运行 ,也会出现这种情况sudo pip <anything>,而不是sudo -H pip <anything>。似乎是无害的。

You are using pip version 9.0.1, however version 10.0.1 is available.  
You should consider upgrading via the 'pip install --upgrade pip' command.

我已经有 pip 10.0.1 – 这就是我看不到这个的原因。

除了这些警告之外,据我所知,两个包都已正确卸载。

关于需要sudo,我并不感到惊讶,因为通常pip install *会在系统范围内安装软件包,并且您不太可能在/usr/local/lib/python*没有 root 的情况下写入。 pip 中存在参数--user来解决这个问题,更详细的答案在这里:https://stackoverflow.com/questions/42988977/what-is-the-purpose-pip-install-user

相关内容