Why do python .pyc files contain the absolute path of their source code, instead of a relative path or something else?
A typical __init__.pyc from Python 2.7 on Ubuntu:
\ufffd\ufffd\ufffdOc@sddlTdS(i\ufffd\ufffd\ufffd\ufffd(t*N(tdbapi2(((s&/usr/lib/python2.7/sqlite3/__init__.py<module>s
asked Jun 25, 2012 at 14:52
joeforker
42.1k41 gold badges159 silver badges259 bronze badges
1 Answer 1
To give the information in tracebacks. See for instance http://docs.python.org/library/compileall#cmdoption-compileall-d
answered Jun 27, 2012 at 1:15
merwok
6,9051 gold badge31 silver badges42 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
Peter Hansen
Note that Éric's link leads to the "-d" option, which can be used to get relative paths into .pyc files instead of the usual absolute path.
Smit Johnth
What would happen if these files are moved to another machine and the paths don't match anymore?
merwok
The information reported in some tracebacks would be wrong.
lang-py
a.pyfile, import it from the interactive prompt, and then runstrings a.pyc.importfrom another folder, you'll probably see the full path (just tried).