[Python-Dev] __file__ is not always an absolute path

Christian Heimes lists at cheimes.de
Sun Feb 7 01:04:27 CET 2010


Guido van Rossum wrote:
> What we do instead, is code in site.py that walks over the elements of
> sys.path and turns them into absolute paths. However this code runs
> before '' is inserted in the front of sys.path, so that the initial
> value of sys.path is ''.
> 
> You may want to print the value of sys.path at various points to see
> for yourself.

I ran into the issue on Debian or Ubuntu (can't remember) several years
ago. The post-install script of the Python package did something like
"cd /usr/lib/pythonX.Y && ./compileall.py", so all pyc files were
created relative to the library root of Python. The __file__ attribute
of all pre-compiled Python files were relative, too.

Christian


More information about the Python-Dev mailing list