cancel
Showing results for 
Search instead for 
Did you mean: 
missing-QuestionPost
cancel
Showing results for 
Search instead for 
Did you mean: 

Why is the current path different when executing a Notebook from Repos vs Workspace?

Duy
New Contributor II

When executing the same Notebook from Repos and Workspace, the current path (`os.getcwd()`) is different:

  • Repos=/Workspace/Repos/USERID/REPONAME.ide/pricing
  • Workspace=/home/spark-1636b562-0ce7-473b-bb17-56

The issue is the Databricks VScode extension recommends switching from Repos to Workspace, but then all the notebook code containing relative path to the notebook doesn't work anymore.

Would it be possible to have Workspace behave the same way as Repos?

1 REPLY 1

Duy
New Contributor II

Found a work around:

``` Python

import os

notebook_dir = os.path.dirname(dbutils.notebook.entry_point.getDbutils().notebook().getContext().notebookPath().get())

notebook_dir = "/Workspace" + notebook_dir

current_dir = os.getcwd()

if current_dir != notebook_dir:

    print(f"Switching current dir to: {notebook_dir}")

    os.chdir(notebook_dir)

```

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!

Sign Up Now