简体   繁体   English

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

[英]discrepancy in numbers of kernels in Jupyter notebook and Anaconda-Navigator

I am running python with Ananconda, and when I load my jupyter notebook, I see that there are 6 kernels available (see image): 我正在用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

具有6个内核,Python和R的Jupyter笔记本

But conda and anaconda-navigator show three environments: 但是conda和anaconda-navigator显示了三种环境:

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

具有3个内核的Anaconda Navigator,Python和R

Furthermore, 此外,

conda info --json

Returns this: 返回此:

{
  "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"
}

How can I reconcile what the jupyter notebook has and what conda reports? 我如何调和jupyter笔记本的内容和conda报告的内容? How can I delete some of the environments reported by Jupyter notebook? 如何删除Jupyter Notebook报告的某些环境? This issue is creating with some libraries that I think are loaded in an environment, but end up in one of the "ghost" environments. 这个问题是由一些我认为已加载到环境中但最终出现在“鬼”环境中的库造成的。

Conda ships with nb_conda_kernels , which bypass the normal kernel mechanism; Conda附带了nb_conda_kernels ,它绕过了常规的内核机制。 thus not all program of your computer can see all the kernels. 因此,并非您计算机的所有程序都能看到所有内核。

nb_conda_kernels is meant to automatically expose any conda env as a possible kernel. nb_conda_kernels旨在自动将任何conda env公开为可能的内核。 It does (or at least did) that only for the notebook server, thus you seeing more kernels from within the notebook UI. 它确实(或至少确实如此)仅针对笔记本服务器,因此您可以在笔记本UI中看到更多内核。

This has advantages : no more manual registering of kernels – and disadvantages : many other piece of software can't see al the kernels; 它具有优点:不再需要手动注册内核-缺点:许多其他软件都看不到内核; notably, Atom, Nteract, Nbconvert, and other lower level tools as well, and the issues you are mentioning. 值得注意的是,还有Atom,Nteract,Nbconvert和其他较低级别的工具,以及您提到的问题。

You can deactivate nb_conda_kernel by looking at your jupyter configuration files and remove the options anaconda has enabled; 您可以通过查看jupyter配置文件来停用nb_conda_kernel并删除anaconda启用的选项; uninstall nb_conda_kernels. 卸载nb_conda_kernels。 Then install kernelspec the classic way . 然后以经典方式安装kernelspec。

IPython kernels != conda environments. IPython内核!= conda环境。 You might have environments with multiple kernels (as in your case environments 'P34' and 'R' have 2 kernels each - for R and Python), or there might be environments without IPython kernels at all. 您可能具有多个内核的环境(在您的情况下,“ P34”和“ R”每个都有2个内核-用于R和Python),或者可能有完全没有IPython内核的环境。

If you want to remove a conda environment, you do that with conda env remove -n ENV_NAME command. 如果要删除conda环境,请使用conda env remove -n ENV_NAME命令执行此操作。

If you want to detach the kernel from Jupyter without removing the whole environment, you can delete the corresponding kernel spec folder. 如果要在不删除整个环境的情况下从Jupyter分离内核,则可以删除相应的内核spec文件夹。 See my answer to your other question for the details on how to find the kernel spec folder. 有关如何查找内核spec文件夹的详细信息,请参见我对其他问题的回答

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM