FAQ
I have looked around for a good howto setup PYTHONPATH on Mac os x
10.5 Although I get many results I am not sure which is correct. I am not
sure if it is different for 10.5 over previous versions. Does anyone know of
a well documented set of instructions.
In my python scripts I specify which python I want to use like this
#!/Library/Frameworks/Python.framework/Versions/4.1.30101/bin/python

Is there a way to specify a module location or working directory? Which is
best? Or should I just add location to PYTHONPATH?


Thanks
Vincent Davis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090225/65e76e8f/attachment.htm>

Search Discussions

  • Philip Semanchuk at Feb 26, 2009 at 12:48 am

    On Feb 25, 2009, at 3:20 PM, Vincent Davis wrote:

    I have looked around for a good howto setup PYTHONPATH on Mac os x
    10.5 Although I get many results I am not sure which is correct. I
    am not
    sure if it is different for 10.5 over previous versions. Does anyone
    know of
    a well documented set of instructions.

    Is there a way to specify a module location or working directory?
    Which is
    best? Or should I just add location to PYTHONPATH?

    Hi Vincent,
    There are different instructions on how to set PYTHONPATH because it
    solves a problem (how to organize one's Python modules) that has more
    than one solution. It's sort of like asking "How should I organize my
    email?" Different strokes for different folks.

    Me, I don't use PYTHONPATH at all. Most of the stuff I want to import
    is already available in site-packages. If not, I can add a .pth file
    to site-packages that tells Python where to find the source. You can
    read about .pth files here:
    http://docs.python.org/library/site.html

    In my python scripts I specify which python I want to use like this
    #!/Library/Frameworks/Python.framework/Versions/4.1.30101/bin/python
    Yikes! Your scripts won't be too portable then, will they? I'm on OS X
    10.5 and I don't have a directory like that. A common, more portable
    alternative is this:

    #!/usr/bin/env python

    That relies (obviously) on /usr/bin/env being present which means that
    your scripts won't work on Windows machines, for instance. But it's a
    whole lot more portable than what you've got now. You don't need a
    shebang line at all if you're willing to launch your scripts by typing
    `python foo.py` at the command line. That will merely execute
    whichever python appears first in your path. I used to always use the /
    usr/bin/env shebang line that I described above, but I do so less
    often now. It's one less dependency to deal with.

    So, in short, PYTHONPATH doesn't need to be set at all, and you can
    switch the shebang line to this:

    #!/usr/bin/env python

    Or do away with it entirely.

    This isn't a complete answer but has it been at least somewhat helpful?

    Cheers
    Philip
  • Python Nutter at Feb 26, 2009 at 7:09 am
    +1 for site packages and standard shebang, still lets you launch with
    python first followed by .py file or <big long path to a specific
    python> followed by .py file

    also for some clues, just open up a terminal in your Mac OS X computer
    and check out your exports your PATH will be different depending on
    all the software and development environments you may or may not be
    using on your Mac, in particular:

    declare -x PATH="/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/Current/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin"

    declare -x PYTHONSTARTUP="/Users/pythonnutter/.pythonstartup"

    for the ultra curious, my custom python startup:

    $cat .pythonstartup
    # python startup file
    import readline
    import rlcompleter
    import atexit
    import os
    # tab completion
    readline.parse_and_bind('tab: complete')
    # history file
    histfile = os.path.join(os.environ['HOME'], '.pythonhistory')
    try:
    readline.read_history_file(histfile)
    except IOError:
    pass
    atexit.register(readline.write_history_file, histfile)
    del os, histfile, readline, rlcompleter



    On Windows you don't have much control in standard batch files but the
    way I keep my Windows box (at work mind you, none at home)
    multi-python'd

    is I configure the environment for Framework 2.5.4, and all the path
    environment variables are configured for the standard directory and
    the scripts subdirectory.

    in 25's scripts is go26.bat which just pre-pends the 2.6.1 path on the
    head of PATH, and of course a go3.bat that pre-pends in 3.0.1

    if you want to get fancy, since there is no pop in batch files that I
    know of, you could drop a .py script in to read in PATH, pop off two
    entries and modify the environment PATH so you fall back down the tree
    (might need some list reversing in there to finish the massaging for
    pops)

    most times I get by with just exiting the terminal session in windows
    and a new cmd session will once again take on the defaults for 2.5.4

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedFeb 25, '09 at 8:20p
activeFeb 26, '09 at 7:09a
posts3
users3
websitepython.org

People

Translate

site design / logo © 2023 Grokbase