Sreejith Menon Sreejith Menon - 1 year ago 132
Python Question

Setting a default sys.path for IPython Notebook

I have all my .py files inside a folder script and all my IPython-notebooks under a folder named Notebook.

There are multiple cross dependencies for each notebook file on one or more files on script.


on top of every notebook seems cumbersome and I am hoping there is a way to add a default lookup path just like we add

Now I do the following:

import sys
sys.path.append("<path where exists>)
import DeriveFinalResultSet as drs

I wish to have a setting where I can do the below:

import DeriveFinalResultSet as drs

Answer Source

After some research I realized changing PYTHONPATH in .bash_profile should do the trick.

Here are the two lines that I added to my .bash_profile

PYTHONPATH="<path where exists>:$PYTHONPATH"

To verify, I did the following after opening a fresh IPython Notebook.

import sys
['', '**<path where exists>**', '<some path>Google Drive/Project/AnimalPhotoBias/Notebooks', '<some path>anaconda/lib/', '<some path>anaconda/lib/python3.5', '<some path>anaconda/lib/python3.5/plat-darwin', '<some path>anaconda/lib/python3.5/lib-dynload', '<some path>anaconda/lib/python3.5/site-packages/Sphinx-1.3.5-py3.5.egg', '<some path>anaconda/lib/python3.5/site-packages/setuptools-20.3-py3.5.egg', '<some path>anaconda/lib/python3.5/site-packages', '<some path>anaconda/lib/python3.5/site-packages/aeosa', '<some path>anaconda/lib/python3.5/site-packages/IPython/extensions', '<some path>.ipython']
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download