pyo contains absolute paths

D

David Siroky

Hi!

When I "compile" my python files with "python -OO ...." into pyo files
then they still contain absolute paths of the source files which is
undesirable for me. How can I deal with that?

Thank you.

David
 
P

Peter Hansen

David said:
When I "compile" my python files with "python -OO ...." into pyo files
then they still contain absolute paths of the source files which is
undesirable for me. How can I deal with that?

Don't do that?

Delete the pyo files?

Stop using Python?

I could guess at a few more possibilities, but since you don't actually
say what you *want* to happen, just what you don't want to happen, there
are an infinite number of ways to satisfy you right now. <wink>

(Hint #1: absolute paths are always, AFAIK, put into the .pyc or .pyo
files.)

(Hint #2: maybe explaining why you don't want this to happen would help
too, since that will probably determine the "best" solution.)

-Peter
 
N

ncf

Python is compiling the files with absolute paths because it is much
faster to load a file when you know where it is, than to have to find
it and then load it.

I'm guessing you're wondering this so you can distribute it compiled or
such? If so, I wouldn't do that in the first place. Python's compiled
files might be version/architecture dependant.

-NcF
 
D

David Siroky

V Sat, 09 Jul 2005 10:22:06 -0400, Peter Hansen napsal(a):
Don't do that?

Delete the pyo files?

Stop using Python?

I could guess at a few more possibilities, but since you don't actually
say what you *want* to happen, just what you don't want to happen, there
are an infinite number of ways to satisfy you right now. <wink>

(Hint #1: absolute paths are always, AFAIK, put into the .pyc or .pyo
files.)

(Hint #2: maybe explaining why you don't want this to happen would help
too, since that will probably determine the "best" solution.)

-Peter

I want to write a commercial application in Python and I don't want the
customer to see the source code and absolute paths of my modules which
have btw. the same base path as the main module so I would expect only
relative paths in the compiled files.

David
 
D

David Siroky

V Sat, 09 Jul 2005 11:48:51 -0700, ncf napsal(a):
Python is compiling the files with absolute paths because it is much
faster to load a file when you know where it is, than to have to find
it and then load it.

I'm guessing you're wondering this so you can distribute it compiled or
such? If so, I wouldn't do that in the first place. Python's compiled
files might be version/architecture dependant.

-NcF

I want to write a commercial application in Python and I don't want the
customer to see the source code and absolute paths of my modules which
have btw. the same base path as the main module so I would expect only
relative paths in the compiled files.

David
 
M

Michael Hudson

David Siroky said:
Hi!

When I "compile" my python files with "python -OO ...." into pyo files
then they still contain absolute paths of the source files which is
undesirable for me. How can I deal with that?

Are you trying to save space? In 2.4 and later each code object will
contain the same copy of the absolute path, so you can't save that
much space.

There are probably ways to make .pycs that have a path of "", if you
really want (see py_compile in the stdlib).

Cheers,
mwh
 
D

Daniel Dittmar

David said:
When I "compile" my python files with "python -OO ...." into pyo files
then they still contain absolute paths of the source files which is
undesirable for me. How can I deal with that?

Use the script compileall.py (in Lib) to compile all the files. This
script has an option -d <dir> that allows to set the directory name
compiled into the .pyo files.

From the help: "-d destdir: purported directory name for error messages"

Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top