4

I want to add a permanent PYTHONPATH using Jupyter Notebook to be able to access the data from a particular directory or folder. I have read that we could use JUPYTER_PATH for it.

Could someone tell me a step wise instruction on how to do it. I am new to it and the documentation was not very clear.

For example sake lets say my path is as follows: C:\ENG\Fin_trade\ION

Sinto
  • 3,915
  • 11
  • 36
  • 70
A.DS
  • 216
  • 1
  • 4
  • 14

1 Answers1

4

For a script that needs to reference your directory, you can do the following.

Say you have the file foo.py containing the class Foo in your directory C:\ENG\Fin_trade\ION

import os
import sys

new_path = r'C:\ENG\Fin_trade\ION'
sys.path.append(new_path)

import foo

Foo()
Oppy
  • 2,662
  • 16
  • 22
  • Here you seem to be giving a piece of code to run inside each notebook. Sinto asks how "to add a permanent PYTHONPATH", meaning, as I read it, put it in the path before any code *inside* a Jupyter notebook is run. Is there a configuration file where we should put your code snippet to have this effect? – SteveWithamDuplicate Jun 16 '19 at 20:10
  • Each operating system has its own method of udating environment variables. You need to search for a solution for the particular OS that you use. – Oppy Jun 24 '19 at 10:44