1

I want Jupyter Lab to use the directory I launch it from on the command prompt. However, it seems to be defaulting to C:\Users\[USERNAME]\AppData\Local\Temp.

I confirm this by running the following:

import inspect
inspect.getfile(inspect.currentframe())

always returns 'C:\\Users\\[USERNAME]\\AppData\\Local\\Temp\\ipykernel_16200\\3653608800.py' regardless of the directory that I launched Jupyter Lab from. Any ideas on how to fix this?


Details:

On other computers/Anaconda installs, I have been able use this command sequence successfully to obtain the working directory and then point to other files relative to it (i.e., add to the system path to support importing modules). I don't understand why it isn't working on this new install. I have not run a --generate-config command, so there does not appear to be any relevant global config settings interfering here.

I am running Windows 10 with Anaconda 2022.05, JupyterLab version 3.3.2

The solutions presented here do not work for me:

  1. Launching with jupyer lab . does not fix the issue
  2. Launching with jupyter lab --notebook-dir=. does not fix the issue
  3. Launching with jupyter lab --notebook-dir=$pwd does not fix the issue
elsevers
  • 532
  • 1
  • 4
  • 16

1 Answers1

0

The solution is found in @rv.kvetch's and @Carlo's comments:

Use the os.getcwd() function instead of inspect.currentframe() (or use pwd!).

This code does what I need for finding my working directory (and adding relative paths):

import os
current_folder = os.getcwd()
elsevers
  • 532
  • 1
  • 4
  • 16