6

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

1

1 Answer 1

6

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()
Sign up to request clarification or add additional context in comments.

3 Comments

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?
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.
This answer does not always work. If inside the package foo there is a call to a method that's in ION then that method will not be found. As for setting the environment variable PYTHONPATH, this requires launching Jupyter again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.