PYTHONPATH problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim Isakson

    PYTHONPATH problems

    OK - I just checked Programming Python out from the library, and am
    enjoying seeing the examples (I've dabbled in Python some previously, but
    an trying to expand my knowledge a bit).

    I'm having a problem getting the PYTHONPATH to work - I've got the
    variable set in the shell (and exported), and it's showing up when I do
    this:

    -- Begin --
    Python 2.2.2 (#2, Feb 5 2003, 10:40:08) [GCC 3.2.1 (Mandrake Linux 9.1
    3.2.1-5mdk)] on linux-i386 Type "help", "copyright" , "credits" or
    "license" for more information.[color=blue][color=green][color=darkred]
    >>> import sys
    >>> print sys.path[/color][/color][/color]
    ['', '/home/tim/python/PP/Examples', '/usr/lib/python2.2',
    '/usr/lib/python2.2/plat-linux-i386', '/usr/lib/python2.2/lib-tk',
    '/usr/lib/python2.2/lib-dynload', '/usr/lib/python2.2/site-packages'][color=blue][color=green][color=darkred]
    >>>
    >>>[/color][/color][/color]
    -- End --

    However, it isn't finding any of the modules in the directory tree that
    begins under /home/tim/python/PP/Examples (it's not having any problems
    with the standard modules - as evidenced by the import of sys above).

    I'm at a loss - any thoughts on what I'm doing incorrectly?

    Thanks for any assistance!

    Tim
  • Erik Max Francis

    #2
    Re: PYTHONPATH problems

    Tim Isakson wrote:
    [color=blue]
    > However, it isn't finding any of the modules in the directory tree
    > that
    > begins under /home/tim/python/PP/Examples (it's not having any
    > problems
    > with the standard modules - as evidenced by the import of sys above).[/color]

    We'll need to see the files contained therein, what their permissions
    are, and what their contents are. Do they have the right permissions?
    Do they end in .py? Are you importing the module exactly as it is name
    (less the .py extension)?

    --
    Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
    __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
    / \
    \__/ Sometimes there's no point in giving up.
    -- Louis Wu

    Comment

    • Rene Pijlman

      #3
      Re: PYTHONPATH problems

      Tim Isakson:[color=blue]
      >I'm having a problem getting the PYTHONPATH to work - I've got the
      >variable set in the shell (and exported), and it's showing up when I do
      >this:[/color]

      So why do you think the problem has to do with PYTHONPATH? Perhaps there's
      something wrong with your import statement, the name of the files, ...
      Tell us more.

      --
      René Pijlman

      Comment

      • Fredrik Lundh

        #4
        Re: PYTHONPATH problems

        Tim Isakson wrote:
        [color=blue]
        > However, it isn't finding any of the modules in the directory tree that
        > begins under /home/tim/python/PP/Examples (it's not having any problems
        > with the standard modules - as evidenced by the import of sys above).[/color]

        "sys" is a built-in module; Python finds that one without even looking
        at the path.
        [color=blue]
        > I'm at a loss - any thoughts on what I'm doing incorrectly?
        >
        > Thanks for any assistance![/color]

        running Python with the "-vv" flag might provide you with some
        additional clues:

        $ python -vv[color=blue][color=green][color=darkred]
        >>> import mymodule[/color][/color][/color]
        # trying mymodule.so
        # trying mymodulemodule. so
        # trying mymodule.py
        # trying mymodule.pyc
        # trying /mysystem/lib/python2.1/mymodule.so
        # trying /mysystem/lib/python2.1/mymodulemodule. so
        /.../
        # trying /mysystem/lib/python2.1/site-packages/PIL/mymodule.py
        # trying /mysystem/lib/python2.1/site-packages/PIL/mymodule.pyc
        Traceback (most recent call last):
        File "<stdin>", line 1, in ?
        ImportError: No module named mymodule

        (also note that you must have read access to the scripts; if Python
        cannot read a file, it treats it as if it didn't exist)

        </F>




        Comment

        • Tim Isakson

          #5
          Re: PYTHONPATH problems

          On Thu, 20 Nov 2003 11:13:23 +0100, Fredrik Lundh wrote:
          [color=blue]
          > Tim Isakson wrote:
          >[color=green]
          >> However, it isn't finding any of the modules in the directory tree that
          >> begins under /home/tim/python/PP/Examples (it's not having any problems
          >> with the standard modules - as evidenced by the import of sys above).[/color]
          >
          > "sys" is a built-in module; Python finds that one without even looking at
          > the path.
          >[color=green]
          >> I'm at a loss - any thoughts on what I'm doing incorrectly?
          >>
          >> Thanks for any assistance![/color]
          >
          > running Python with the "-vv" flag might provide you with some additional
          > clues:
          >
          > $ python -vv[color=green][color=darkred]
          > >>> import mymodule[/color][/color]
          > # trying mymodule.so
          > # trying mymodulemodule. so
          > # trying mymodule.py
          > # trying mymodule.pyc
          > # trying /mysystem/lib/python2.1/mymodule.so # trying
          > /mysystem/lib/python2.1/mymodulemodule. so /.../
          > # trying /mysystem/lib/python2.1/site-packages/PIL/mymodule.py #
          > trying /mysystem/lib/python2.1/site-packages/PIL/mymodule.pyc
          > Traceback (most recent call last):
          > File "<stdin>", line 1, in ?
          > ImportError: No module named mymodule
          >
          > (also note that you must have read access to the scripts; if Python cannot
          > read a file, it treats it as if it didn't exist)
          >
          > </F>[/color]

          Thanks for the -vv flag tip - it helped some.

          Sadly (for me, at least), the problem turned out to be user error - I was
          using BASH syntax for the path while within Python, and needless to say,
          that didn't do the trick.

          Once I changed the imports to use '.' as the delimiter, things worked
          fine.

          Thanks for your assistance!

          Tim

          Comment

          Working...