File paths printed in stack trace are where Python was built???

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Nov 29 00:36:00 EST 2008


On Fri, 28 Nov 2008 19:22:11 -0800, Roy Smith wrote:

> We distribute Python internally by building it in one place, and then
> distributing images of the entire install area to wherever it's needed. 
> I just noticed something strange; when I got an error which caused a
> stack trace, the file paths in the printed stack trace refer to the
> directory where Python was built.

My guess is that your build process generates the .pyc files, and that 
they include a reference to the source location at the time they were 
built. I bet that if you remove the .pyc files and let them get re-
generated the problem will go away.

> Is there a way to make the stacktraces point to where Python is 
> running from, instead of where it was built?

But the stack trace doesn't point to where Python is running from, it 
points to where the module is. Since you're (probably) running from a 
compiled module, the location of the .pyc file is useless, and you need 
to know where the .py file is. But how can the .pyc file know where 
the .py file is at runtime unless it is cached at compile time? I suppose 
Python could use some sort of heuristic to guess, but that would be slow 
and error-prone.


-- 
Steven



More information about the Python-list mailing list