Newbie Question: How to use a .pth file on a Macintosh

Discussion in 'Python' started by Robbie, May 24, 2008.

  1. Robbie

    Robbie Guest

    Hello All,

    Hopefully this is an easy question: I'd like to use a .pth file on my
    Macintosh so that I can easily import modules that I've created in my
    own working directory. I've created a file called Robbie.pth. It
    includes a single line:

    I can't seem to figure out where to put this file so that Python will
    recognize it when I start it up. I know that the path is correct
    because if I do the command sys.path.append('/Robbie/PythonWork') then
    everything works as expected. I just don't want to have to execute
    this command every time I start Python.

    I've looked at what's in sys.path, and have tried putting the file in
    various of the directories listed, to no avail. I've also tried
    putting it in the same directory where IDLE is (/Applications/
    MacPython 2.5) and that doesn't work either.

    What am I missing?

    FYI I'm running MaxOS 10.4.8 and Python 2.5,

    Thank you in advance for the help.

    Robbie, May 24, 2008
    1. Advertisements

  2. Robbie

    J Peyret Guest

    Hmmm, for lack of a better response, here are some suggestions, based
    on what I've seen on Windows+Linux.

    #1 put the .pth in the site-packages directory (this is what I do on
    Linux). I think Python considers it special and looks for pth.

    you can probably get that directory from doing

    import sys
    for i in sys.path:
    print i

    #2 put the .pth in the directory where the python executable is
    located (this is less messy on Windows than on Linux or OS X)

    which python (run on the OS X terminal command shell) should give you
    an idea of where that is.

    #3 Another idea is to use the Finder to find _other_ *.pth files that
    may exist and put yours in the same location.

    Best of luck.
    J Peyret, May 25, 2008
    1. Advertisements

  3. Robbie


    you put your pth file in (same configuration:

    , May 25, 2008
  4. Robbie wrote:
    > I can't seem to figure out where to put this file so that Python will
    > recognize it when I start it up.

    You need to put this file in your site-packages directory.
    To get the location of your site-packages directory, type in Python
    interactive shell:

    from distutils.sysconfig import get_python_lib
    print get_python_lib()

    -- Ivan
    Ivan Illarionov, May 25, 2008
    1. Advertisements

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. Benjamin Rutt

    .pth files question

    Benjamin Rutt, Sep 2, 2005, in forum: Python
    Peter Hansen
    Sep 2, 2005
  2. Replies:
  3. Jim

    where to put .pth file

    Jim, Oct 13, 2006, in forum: Python
  4. Alan Isaac

    allow scripts to use .pth files?

    Alan Isaac, Jul 3, 2007, in forum: Python
    Jul 12, 2007
  5. oyster

    a module.pth question

    oyster, Jul 14, 2008, in forum: Python
    Mike Driscoll
    Jul 14, 2008

Share This Page