Import - interpreter works but .py import does not

Discussion in 'Python' started by John Boy, Mar 10, 2008.

  1. John Boy

    John Boy Guest

    First post and very much a newbie to Python. Have 2.5 on Linux (GG). I
    think I have set up PYTHONPATH correctly in that I can import a module
    apply_bp and it complains about line 20 in apply_bp which is:

    import sys, aipy, numpy, os

    At the interpreter prompt, however, I can import sys, numpy etc. and
    can do dir() and see the entry points so I think my overall
    installation is OK.

    Why does line not work ? Also I would have thought that when I pre-
    imported sys et al that they would be in the symbol table so that the
    import line would be a noop.

    Thanks,

    Slainte,

    John
     
    John Boy, Mar 10, 2008
    #1
    1. Advertising

  2. John Boy

    John Machin Guest

    On Mar 10, 1:59 pm, John Boy <> wrote:
    > First post and very much a newbie to Python. Have 2.5 on Linux (GG). I
    > think I have set up PYTHONPATH correctly in that I can import a module
    > apply_bp and it complains about line 20 in apply_bp which is:
    >
    > import sys, aipy, numpy, os


    Please get used to showing the error message. "it complains about line
    x" is not very helpful. Fortunately in this case we can guess that it
    is "complaining" about inability to import either aipy or numpy (sys
    and os are built-in).

    >
    > At the interpreter prompt, however, I can import sys, numpy etc. and
    > can do dir() and see the entry points so I think my overall
    > installation is OK.
    >
    > Why does line not work ?


    More information please.

    At the interpreter prompt, do this:
    import sys
    sys.path
    import aipy; aipy.__file__
    import numpy; numpy.__file__
    and show us the result.
    Change the offending line in your apply_bp module to
    import sys
    print sys.path
    import os, aipy, numpy
    and show us ALL of the output.
    At the shell prompt, do whatever it takes to display the contents of
    PYTHONPATH, and show us the results.

    > Also I would have thought that when I pre-
    > imported sys et al that they would be in the symbol table so that the
    > import line would be a noop.


    The concept of "preimporting" a module is novel to me. Importing a
    module at the interpreter prompt doesn't persist when you exit the
    interpreter and then (implicitly) start up another interpreter task to
    run your script. Importing a module in your script puts the module in
    the script's namespace, which is quite distinct from the namespace of
    the apply_bp (or any other) module. If those two possibilities don't
    cover what you mean, please explain.
     
    John Machin, Mar 10, 2008
    #2
    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. Christian Seberino
    Replies:
    2
    Views:
    465
    Christian Seberino
    Feb 12, 2004
  2. F. GEIGER
    Replies:
    3
    Views:
    816
    F. GEIGER
    Aug 6, 2004
  3. Bill Davy
    Replies:
    0
    Views:
    739
    Bill Davy
    May 12, 2005
  4. David Wang
    Replies:
    0
    Views:
    760
    David Wang
    Dec 1, 2006
  5. abargaddon
    Replies:
    1
    Views:
    220
    clintmazur
    Feb 4, 2008
Loading...

Share This Page