Python - Are there more search paths than in sys.path? -
Python - Are there more search paths than in sys.path? -
i thought sys.path finish list of all search paths python modules.
however, on ubuntu machine, '/usr/local/lib/python2.6/dist-packages/' modules , path not in sys.path. , can still import module on path.
edit, not true: if set sys.path empty list, can still import path.
where implicit knowledge of dist-packages path come from? , there other paths in implicit grouping of search paths, or whatever is?
edit: seems sec part of post not true. indeed, "sys.path = []", mean can not import anything, not current working directory. apologies.
note mention of installation-dependent default in following:
6.1.2. module search path
when module named spam
imported, interpreter searches file named spam.py
in directory containing input script , in list of directories specified environment variable pythonpath
. has same syntax shell variable path
, is, list of directory names. when pythonpath
not set, or when file not found there, search continues in installation-dependent default path; on unix, .:/usr/local/lib/python
.
actually, modules searched in list of directories given variable sys.path
initialized directory containing input script (or current directory), pythonpath
, the installation-dependent default. allows python programs know they’re doing modify or replace module search path. note because directory containing script beingness run on search path, of import script not have same name standard module, or python effort load script module when module imported. error. see section standard modules more information.
edit on ubuntu box, /usr/local/lib/python2.6/dist-packages
nowadays in sys.path
. if clear sys.path
, seek import module above directory, no longer works. suggests interpreter has no implicit knowledge of directory , finds via sys.path
.
edit when conduct experiments, create sure modify sys.path
right @ start of python session. if import x
, clear sys.path
, , import x
again, latter not fail though x
no longer on sys.path
.
python sys.path module-search-path
Comments
Post a Comment