Jupyter笔记本和Anaconda-Navigator中内核数量的差异

时间:2017-09-17 19:02:54

标签: python anaconda jupyter-notebook

我正在使用Ananconda运行python,当我加载我的jupyter笔记本时,我看到有6个内核可用(见图):

Last login: Sun Sep 17 12:42:58 on ttys001
MacBook:~ user1$ jupyter notebook
[I 14:53:55.642 NotebookApp] [nb_conda_kernels] enabled, 6 kernels found
[I 14:53:56.470 NotebookApp] JupyterLab alpha preview extension loaded from /Users/user/anaconda/lib/python2.7/site-packages/jupyterlab
[I 14:53:56.471 NotebookApp] Running the core application with no additional extensions or settings
[I 14:53:57.374 NotebookApp] [nb_anacondacloud] enabled
[I 14:53:57.379 NotebookApp] [nb_conda] enabled
[I 14:53:57.451 NotebookApp] ✓ nbpresent HTML export ENABLED
[W 14:53:57.452 NotebookApp] ✗ nbpresent PDF export DISABLED: No module named nbbrowserpdf.exporters.pdf
[I 14:53:57.457 NotebookApp] Serving notebooks from local directory: /Users/user

Jupyter notebook with 6 kernels, Python and R

但是conda和anaconda-navigator展示了三种环境:

conda info --envs
# conda environments:
#
P34                      /Users/user/anaconda/envs/P34
R                        /Users/user/anaconda/envs/R
root                  *  /Users/user/anaconda

Anaconda Navigator with 3 kernels, Python and R

此外,

conda info --json

返回:

{
  "GID": 20, 
  "UID": 503, 
  "channels": [
    "https://conda.anaconda.org/anaconda-fusion/osx-64", 
    "https://conda.anaconda.org/anaconda-fusion/noarch", 
    "https://conda.anaconda.org/r/osx-64", 
    "https://conda.anaconda.org/r/noarch", 
    "https://repo.continuum.io/pkgs/free/osx-64", 
    "https://repo.continuum.io/pkgs/free/noarch", 
    "https://repo.continuum.io/pkgs/r/osx-64", 
    "https://repo.continuum.io/pkgs/r/noarch", 
    "https://repo.continuum.io/pkgs/pro/osx-64", 
    "https://repo.continuum.io/pkgs/pro/noarch"
  ], 
  "conda_build_version": "2.0.2", 
  "conda_env_version": "4.3.25", 
  "conda_location": "/Users/user/anaconda/lib/python2.7/site-packages/conda", 
  "conda_prefix": "/Users/user/anaconda", 
  "conda_private": false, 
  "conda_version": "4.3.25", 
  "default_prefix": "/Users/user/anaconda", 
  "env_vars": {
    "CIO_TEST": "<not set>", 
    "CONDA_DEFAULT_ENV": "<not set>", 
    "CONDA_ENVS_PATH": "<not set>", 
    "DYLD_LIBRARY_PATH": "<not set>", 
    "PATH": "/Users/user/Dropbox (Personal)/firefoxdriver_osx/bin:/Users/user/Dropbox (Personal)/chromedriver_osx/bin:/Users/user/anaconda/bin:/Library/Frameworks/Python.framework/Versions/Current/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/TeX/texbin", 
    "PYTHONHOME": "<not set>", 
    "PYTHONPATH": "<not set>"
  }, 
  "envs": [
    "/Users/user/anaconda/envs/P34", 
    "/Users/user/anaconda/envs/R"
  ], 
  "envs_dirs": [
    "/Users/user/anaconda/envs", 
    "/Users/user/.conda/envs"
  ], 
  "netrc_file": null, 
  "offline": false, 
  "pkgs_dirs": [
    "/Users/user/anaconda/pkgs", 
    "/Users/user/.conda/pkgs"
  ], 
  "platform": "osx-64", 
  "python_version": "2.7.13.final.0", 
  "rc_path": "/Users/user/.condarc", 
  "requests_version": "2.14.2", 
  "root_prefix": "/Users/user/anaconda", 
  "root_writable": true, 
  "site_dirs": [], 
  "sys.executable": "/Users/user/anaconda/bin/python", 
  "sys.prefix": "/Users/user/anaconda", 
  "sys.version": "2.7.13 |Anaconda 4.4.0 (x86_64)| (default, Dec 20 2016, 23:05:08) \n[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]", 
  "sys_rc_path": "/Users/user/anaconda/.condarc", 
  "user_agent": "conda/4.3.25 requests/2.14.2 CPython/2.7.13 Darwin/16.7.0 OSX/10.12.6", 
  "user_rc_path": "/Users/user/.condarc"
}

如何协调jupyter笔记本电脑和conda报告的内容?如何删除Jupyter笔记本报告的一些环境?这个问题是创建了一些我认为在环境中加载的库,但最终出现在一个“鬼”环境中。

2 个答案:

答案 0 :(得分:0)

Conda附带nb_conda_kernels,它绕过了正常的内核机制;因此,并非所有计算机程序都能看到所有内核。

nb_conda_kernels旨在自动将任何conda env公开为可能的内核。它确实(或至少确实)仅用于笔记本服务器,因此您可以在笔记本UI中看到更多内核。

这有以下优点:不再需要手动注册内核 - 以及缺点:许多其他软件无法看到内核;值得注意的是,Atom,Nteract,Nbconvert以及其他较低级别的工具,以及您提到的问题。

您可以通过查看您的jupyter配置文件并删除anaconda已启用的选项来停用nb_conda_kernel;卸载nb_conda_kernels。然后安装kernelspec the classic way

答案 1 :(得分:0)

IPython内核!= conda环境。您可能具有多个内核的环境(如您的情况,“ P34”和“ R”每个都有2个内核-用于R和Python),或者可能完全没有IPython内核。

如果要删除conda环境,请使用conda env remove -n ENV_NAME命令。

如果要从Jupyter分离内核而不删除整个环境,则可以删除相应的内核spec文件夹。有关如何查找内核spec文件夹的详细信息,请参见我对其他问题的answer