Unless -S
option is passed to the python
binary, a special site module is imported by default before the execution is passed to your script, or the interactive interpreter. Among other things the module looks for *.pth
files. On each line the *.pth
files should contain either a path to include into sys.path
, or a command to execute. The module as well imports sitecustomize
, and usercustomize
(which can contain arbitrary code, a good way to make your colleagues crazy, if they happen to raise errors) if they exist somewhere in sys.path
.
The problem is though, that the current directory in not in sys.path
when the site
module is imported, that is it is hard to configure your particular script.
I sometimes add the following line at the beginning of my scripts, so that the script would start with searchin for .pth
files in the current directory and adding the missing paths to sys.path
:
# search for *.pth files in the current directory
import site; site.addsitedir('')
ipythonrc
. The new configuration file has the same functionality (and much more), as described in their documentation. – Focus