pyo contains absolute paths

Discussion in 'Python' started by David Siroky, Jul 9, 2005.

  1. David Siroky

    David Siroky Guest

    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
     
    David Siroky, Jul 9, 2005
    #1
    1. Advertising

  2. David Siroky

    Peter Hansen Guest

    David Siroky wrote:
    > 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
     
    Peter Hansen, Jul 9, 2005
    #2
    1. Advertising

  3. David Siroky

    ncf Guest

    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
     
    ncf, Jul 9, 2005
    #3
  4. David Siroky

    David Siroky Guest

    V Sat, 09 Jul 2005 10:22:06 -0400, Peter Hansen napsal(a):

    > David Siroky wrote:
    >> 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


    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
     
    David Siroky, Jul 11, 2005
    #4
  5. David Siroky

    David Siroky Guest

    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
     
    David Siroky, Jul 11, 2005
    #5
  6. David Siroky <> writes:

    > 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

    --
    I located the link but haven't bothered to re-read the article,
    preferring to post nonsense to usenet before checking my facts.
    -- Ben Wolfson, comp.lang.python
     
    Michael Hudson, Jul 11, 2005
    #6
  7. David Siroky wrote:
    > 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
     
    Daniel Dittmar, Jul 11, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Dyer
    Replies:
    5
    Views:
    687
  2. Donald
    Replies:
    1
    Views:
    489
    Roel van der Steen
    Mar 7, 2004
  3. Noah
    Replies:
    5
    Views:
    846
  4. Stef Mientki
    Replies:
    2
    Views:
    429
    Diez B. Roggisch
    Jun 8, 2009
  5. Ohad Lutzky

    Paths, gentleman, paths

    Ohad Lutzky, Nov 6, 2006, in forum: Ruby
    Replies:
    2
    Views:
    223
    David Vallner
    Nov 7, 2006
Loading...

Share This Page