anaconda/nb_conda_kernels

python current working directory set to default when changing kernel

Closed this issue · 2 comments

When launching Jupyter lab from an anaconda prompt and navigating to a notebook residing in e.g. 'DIRPATH', running a cell
import os
os.getcwd()
outputs
'DIRPATH'

After switching the kernel (using the menu) to some other kernel
import os
os.getcwd()
outputs a default directory (in my case 'C:\Users\%USERNAME%')

Switching back to the kernel that launched the Jupyter lab instance restores 'DIRPATH' as the current working directory

Is this the intended behavior?
It makes it hard to use relative paths to e.g. data files in a project.

I'm unable to reproduce this with JupyterLab 4.1.2. Specifically, I can:

  • navigate to a notebook in another directory
  • open it with a native kernel
  • run import os; print(os.getcwd()); it is the current directory
  • change to a kernel in a different environment
  • run import os; print(os.getcwd()); it is still the same directory

I'm going to close this as stale but if you would like to re-open with some testing instructions please do!