FAQ
Hello Pythonistas,

I am trying to get certain (self-written) libraries imported into my
scripts using statements like

"from library import function.py".

But they are not being found.

I think that the pythonpath-variable must be expanded to the location
to this libraries.

But, I can't find any usable information using Google on how to set up
the pythonpath properly.
I don't even know where to look for the pythonpath-variable?

It would be great if anyone could help me out on this?

Thanks,
Eric

Search Discussions

  • Martin Franklin at Oct 24, 2003 at 9:47 am

    On Fri, 2003-10-24 at 10:20, Eric Wichterich wrote:
    Hello Pythonistas,

    I am trying to get certain (self-written) libraries imported into my
    scripts using statements like

    "from library import function.py".
    Is this a typo you do not need the .py on the end
    it should (perhaps) read:

    from library import function

    But they are not being found.

    I think that the pythonpath-variable must be expanded to the location
    to this libraries.

    But, I can't find any usable information using Google on how to set up
    the pythonpath properly.
    I don't even know where to look for the pythonpath-variable?
    The pythonpath (or PYTHONPATH) variable is an environment variable -
    I'm no MAC expert but I expect there is a command you could use to show
    it's value... however from inside a running python program the
    PYTHONPATH variable is stored in sys.path and is a list of paths that
    python will look in for your module / package.

    Python 2.3 (#1, Aug 27 2003, 10:53:10)
    [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    import sys
    sys.path
    ['', '/usr/local/lib/python23.zip', '/usr/local/lib/python2.3',
    '/usr/local/lib/python2.3/plat-linux2',
    '/usr/local/lib/python2.3/lib-tk',
    '/usr/local/lib/python2.3/lib-dynload',
    '/usr/local/lib/python2.3/site-packages',
    '/usr/local/lib/python2.3/site-packages/PIL']
    >>>


    A quick google on PYTHONPATH should point you towards some useful
    information... it is also explained in the (free, online) python
    tutorial
    http://www.python.org/doc/current/tut/node8.html#SECTION008110000000000000000
    It would be great if anyone could help me out on this?

    Thanks,
    Eric

    Regards
    Martin


    --
    Martin Franklin <mfranklin1 at gatwick.westerngeco.slb.com>
  • Eric Wichterich at Oct 24, 2003 at 3:41 pm
    Thank you, Martin,

    I fixed the problem with pythonpath and figured out that there is a
    problem with Apache and CGI, not with importing the library anymore.
    There is something Apache doesn't like. I only get the two different
    errors: Malformed header - or - premature end of file, no further
    details. The python-scripts work fine on a linux server with Apache in
    contrast to Apache on Mac OS X...

    I'll keep working on it. It's just frustrating.

    Eric

    Von: Martin Franklin <mfranklin1 at gatwick.westerngeco.slb.com>
    Datum: Fr, 24. Okt 2003 11:47:01 Europe/Berlin
    An: Python List <python-list at python.org>
    Betreff: Re: How to set pythonpath in Mac OS X?

    On Fri, 2003-10-24 at 10:20, Eric Wichterich wrote:
    Hello Pythonistas,

    I am trying to get certain (self-written) libraries imported into my
    scripts using statements like

    "from library import function.py".
    Is this a typo you do not need the .py on the end
    it should (perhaps) read:

    from library import function

    But they are not being found.

    I think that the pythonpath-variable must be expanded to the location
    to this libraries.

    But, I can't find any usable information using Google on how to set up
    the pythonpath properly.
    I don't even know where to look for the pythonpath-variable?
    The pythonpath (or PYTHONPATH) variable is an environment variable -
    I'm no MAC expert but I expect there is a command you could use to show
    it's value... however from inside a running python program the
    PYTHONPATH variable is stored in sys.path and is a list of paths that
    python will look in for your module / package.

    Python 2.3 (#1, Aug 27 2003, 10:53:10)
    [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    import sys
    sys.path
    ['', '/usr/local/lib/python23.zip', '/usr/local/lib/python2.3',
    '/usr/local/lib/python2.3/plat-linux2',
    '/usr/local/lib/python2.3/lib-tk',
    '/usr/local/lib/python2.3/lib-dynload',
    '/usr/local/lib/python2.3/site-packages',
    '/usr/local/lib/python2.3/site-packages/PIL']

    A quick google on PYTHONPATH should point you towards some useful
    information... it is also explained in the (free, online) python
    tutorial
    http://www.python.org/doc/current/tut/
    node8.html#SECTION008110000000000000000
    It would be great if anyone could help me out on this?

    Thanks,
    Eric

    Regards
    Martin


    --
    Martin Franklin <mfranklin1 at gatwick.westerngeco.slb.com>

  • Jorl Shefner at Oct 24, 2003 at 8:02 pm
    In article <mailman.69.1066987239.702.python-list at python.org>,
    Eric Wichterich wrote:
    Hello Pythonistas,

    I am trying to get certain (self-written) libraries imported into my
    scripts using statements like

    "from library import function.py".

    But they are not being found.

    I think that the pythonpath-variable must be expanded to the location
    to this libraries.

    But, I can't find any usable information using Google on how to set up
    the pythonpath properly.
    I don't even know where to look for the pythonpath-variable?

    It would be great if anyone could help me out on this?

    Thanks,
    Eric
    I simply placed this in my start-up script and it works fine:

    setenv PYTHONPATH /Users/Me/Documents/Python/MyModules

    OS 10.2.8

    J.S.
  • Russell E. Owen at Oct 24, 2003 at 9:46 pm
    In article <mailman.69.1066987239.702.python-list at python.org>,
    Eric Wichterich wrote:
    Hello Pythonistas,

    I am trying to get certain (self-written) libraries imported into my
    scripts using statements like

    "from library import function.py".

    But they are not being found.

    I think that the pythonpath-variable must be expanded to the location
    to this libraries.

    But, I can't find any usable information using Google on how to set up
    the pythonpath properly.
    I don't even know where to look for the pythonpath-variable?

    It would be great if anyone could help me out on this?
    You can define the environment variable PYTHONPATH to include any paths
    you like, and python will read this info when it starts up.

    On MacOS X you have several choices for defining environment variables.
    All work for unix command-line apps, but only can be seen by GUI apps,
    so it's the one I recommend you use: put the information into a file
    .MacOSX/environment.plist (which you will probably have to create).
    Instructions are available at
    <http://www.astro.washington.edu/owen/AquaEnvVar.html>

    If you only care about command-line usage then you can edit ~/.cshrc and
    include a command such as
    setenv PYTHONPATH "/path/one/:path/two:..."
    (note: .cshrc may not be the best choice, but it certainly works).

    Warning: do NOT mix these two techniques. At least in Jaguar,
    environment.plist completely overrides env variables defined or modified
    in .cshrc.

    -- Russell

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedOct 24, '03 at 9:20a
activeOct 24, '03 at 9:46p
posts5
users4
websitepython.org

People

Translate

site design / logo © 2022 Grokbase