I thought that the sys.path was a complete list of all search paths for Python modules.
However, on my Ubuntu machine, ‘/usr/local/lib/python2.6/dist-packages/’ is where almost all my modules are and that path is not in sys.path. And I can still import any module on that path.
EDIT, NOT TRUE: Even if I set the sys.path to the empty list, I can still import from that path.
Where does this implicit knowledge of the dist-packages path come from? And are there any other paths in this implicit group of search paths, or whatever it is?
EDIT: It seems like the second part of my post is not true. Indeed, “sys.path = []”, will mean that I can not import anything, not even from my current working directory. My apologies.
Note the mention of an installation-dependent default in the following:
edit On my Ubuntu box,
/usr/local/lib/python2.6/dist-packagesis present insys.path. If I clearsys.pathand then try to import a module from the above directory, that no longer works. This suggests that the interpreter has no implicit knowledge of that directory and finds it viasys.path.edit When you conduct your experiments, make sure that you modify
sys.pathright at the start of your Python session. If youimport X, then clearsys.path, and thenimport Xagain, the latter will not fail even thoughXis no longer onsys.path.