Search code examples
python-2.7ipythondatanitro

Adding Path To Module Permanently.


I have written a module to be used in the DataNitro iPython shell, but I think the problem is more general than just to the DataNitro shell:

I can successfully import the module when I do the following in the DataNitro iPython shell:

import sys
sys.path.append(path/to/WorkbookFunctions.py)
import WorkbookFunctions as wf

But when I close the shell and open again and do the following:

import sys
sys.path

the path I added previously is not there.

How do I make the path permanent in the sys.path directory?

Thanks


Solution

  • If you want to have a module generally importable when you use Python, you should add it to a folder on the Python path, rather than modify the path. (Typically, you'll use Python27/lib/site-packages on Windows.)

    However, if you're just working with a local file, the best thing to do is to keep it in your working folder: Python will always check the local directory before moving further down the path. In the case of DataNitro, this will be the directory your workbook is in.