Ahmad
Ahmad

Reputation: 9668

How to access directories outside the working directory of jupyter notebook

I know how to set a working directory or initial directory of Jupyter.

How to change the Jupyter start-up folder

However, when I do such, I don't have access to the parent directory of the working directory. I want to set the root directory of Jupyter to home directory to have access to all directories, but I want to have my specific directory (e.g. my notebooks) as the initial directory that the file browser shows initially, so if I wanted I could go up and browse other directories...

Upvotes: 2

Views: 5190

Answers (1)

Ale
Ale

Reputation: 1004

From my jupyter notebook, I start in the following working directory:

import os
os.getcwd()

'C:\\Users\\...\\my_working_dir'

Suppose I want to access the file 'abc.py' in another directory.

I can use this command directly in my jupyter notebook:

import sys
sys.path.insert(0, 'G:/your_path_where_abc_is/')
from abc import ColumnSelector
os.getcwd() # unnecessary: just to show that the working directory is the same as before

'C:\\Users\\...\\my_working_dir'

So that I can load it from another directory without changing my working directory.

Is this what you were looking for?

Upvotes: 2

Related Questions