Windows PATH not adjusted to reflect kernel location / prefix

I want to separate the packages for jupyter from the packages that I need for my calculations. Therefore I am working with multiple IPython kernels for different conda environments.

I have two environments:

  1. IDE_jupyter : environment with just jupyter-lab
  2. test_calcs : an environment with just numpy and ipykernel

I register the test_calcs environment with
python -m ipykernel install --name test_calcs --display-name “For testing only”

this allows me to run jupyter in the first environment and then start a notebook with the “test_calcs”-kernel.

The problem is when I want to import numpy. Numpy fails to load due to the famous library error. This is caused by the fact that the windows PATH environment variable points to the conda environment of the jupyter-environment instead of that of the test_calcs environment:

import os
for p in os.environ['PATH'].split(';'):
    print(p)

gives:

c:\Data\apps\miniconda3\envs\ide_jupyter
c:\Data\apps\miniconda3\envs\ide_jupyter\Library\mingw-w64\bin
c:\Data\apps\miniconda3\envs\ide_jupyter\Library\usr\bin
c:\Data\apps\miniconda3\envs\ide_jupyter\Library\bin
c:\Data\apps\miniconda3\envs\ide_jupyter\Scripts
c:\Data\apps\miniconda3\envs\ide_jupyter\bin
c:\Data\apps\miniconda3\condabin
C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\ia32_win\mpirt
C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\ia32_win\compiler
C:\WINDOWS\system32

now this should have been c:\Data\apps\miniconda3\envs\test_calcs .
The sys.path variable is correct.

I would accept this as a given “ok, so that does not work. Let’s try to find a work-around” except for the fact that with spyder and spyder_kernels the equivalent trick does work.

The work-around is to manually change the path before importing numpy:

import os
os.environ['PATH'] = os.environ['PATH'].replace("ide_jupyter","test_calcs")