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)

```

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group