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:
[ 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:
python -m ipykernel install --name mlflow
However, once in the mlflow
kernel in jupyter, I cannot import the same module, 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:
{
"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. 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. However, it'd still be nice to know how to do the same using the jupyter in base
.
Try giving the full conda python path and see if that resolves it:
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. Using "python -m" may reference the native python outside conda or maybe the python in the base environment. Specifying the full path just ensures that it gets installed in the right environment.
That indeed seems to do the trick! So could you add more details? So the issue was that the kernel is defined to launch the wrong python?
I have edited the answer to provide more info. Please do 'mark as the answer' if this resolves the issue. Thanks.
Thanks,very useful!