简体   繁体   English

Jupyter Notebook kernel 不同于conda环境

[英]Jupyter notebook kernel different from conda environment

I'm encountering problems while trying to reproduce a conda environment in a jupyter notebook kernel. I've created a conda environment, mlflow , and by activating it, I can import mlflow, as you can see below:我在 jupyter notebook kernel 中尝试重现 conda 环境时遇到问题。我创建了一个 conda 环境mlflow ,通过激活它,我可以导入 mlflow,如下所示:

[ 12:36:18 ] ~ base ❯ conda activate mlflow
[ 12:36:21 ] ~ mlflow ❯ python
Python 3.7.0 (default, Jun 28 2018, 08:04:48) [MSC v.1912 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import mlflow
>>>

Then I proceed to install the kernel in jupyter, as:然后我继续在 jupyter 中安装 kernel,如下所示:

python -m ipykernel install --name mlflow

However, once in the mlflow kernel in jupyter, I cannot import the same module, mlflow .但是,一旦在mlflow的 mlflow kernel 中,我就无法导入相同的模块mlflow Why could that be?为什么会这样? It suspect that the issue is that C:\Users\userx\AppData\Roaming\jupyter\kernels\mlflow\kernel.json is pointing to the wrong python:它怀疑问题是C:\Users\userx\AppData\Roaming\jupyter\kernels\mlflow\kernel.json指向错误的 python:

{
 "argv": [
  "C:\\Users\\userx\\Anaconda3\\python.exe",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "mlflow",
 "language": "python"
}

Whereas it should be pointing to the python in the mlflow environment.而它应该指向mlflow环境中的 python。 However, I tried to change it and the caused the notebook to fail when launching.然而,我试图改变它,导致笔记本电脑在启动时失败。

More details:更多细节:

[ 12:39:27 ] ~ base ❯ jupyter --path
config:
    C:\Users\userx\.jupyter
    C:\Users\userx\Anaconda3\etc\jupyter
    C:\ProgramData\jupyter
data:
    C:\Users\userx\AppData\Roaming\jupyter
    C:\Users\userx\Anaconda3\share\jupyter
    C:\ProgramData\jupyter
runtime:
    C:\Users\userx\AppData\Roaming\jupyter\runtime

EDIT编辑

It seems to work if I install jupyter in the environment, and launch a notebook from the environment.如果我在环境中安装 jupyter 并从环境中启动笔记本,这似乎可行。 However, it'd still be nice to know how to do the same using the jupyter in base .但是,如果知道如何使用base中的 jupyter 来做同样的事情,那就太好了。

Try giving the full conda python path and see if that resolves it:尝试提供完整的 conda python 路径,看看是否可以解决问题:

C:\Users\<username>\anaconda\envs\<environment-name>\bin\python -m ipykernel install --name mlflow

The reason ipykernel was not found was because it was not installed in the right python environment.找不到ipykernel的原因是没有安装到正确的python环境。 Using "python -m" may reference the native python outside conda or maybe the python in the base environment.使用“python -m”可以引用 conda 外部的本机 python 或基础环境中的 python。 Specifying the full path just ensures that it gets installed in the right environment.指定完整路径只是确保它安装在正确的环境中。

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

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