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

有帮助吗?

解决方案

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.

其他提示

Alternatively, if you do want to modify your path, you can follow this answer and use .pth files. I, personally, find this very useful.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top