how to check if a module is importable?

Discussion in 'Python' started by Robert P. J. Day, Jan 20, 2010.

  1. finally getting back to clawing my way thru the python 3 book so
    probably a number of newbie questions coming up. first one -- can i
    check if a module is importable (equivalently, exists on sys.path, i
    assume) without trying to import it first?

    i can see that i can use try/except and just run "import" -- is that
    the accepted way to test?

    rday
    --

    ========================================================================
    Robert P. J. Day Waterloo, Ontario, CANADA

    Linux Consulting, Training and Kernel Pedantry.

    Web page: http://crashcourse.ca
    Twitter: http://twitter.com/rpjday
    ========================================================================
     
    Robert P. J. Day, Jan 20, 2010
    #1
    1. Advertising

  2. Robert P. J. Day

    Lie Ryan Guest

    On 01/20/10 19:58, Robert P. J. Day wrote:
    >
    > finally getting back to clawing my way thru the python 3 book so
    > probably a number of newbie questions coming up. first one -- can i
    > check if a module is importable (equivalently, exists on sys.path, i
    > assume) without trying to import it first?
    >
    > i can see that i can use try/except and just run "import" -- is that
    > the accepted way to test?


    check imp.find_module()
     
    Lie Ryan, Jan 20, 2010
    #2
    1. Advertising

  3. On Thu, 21 Jan 2010, Lie Ryan wrote:

    > On 01/20/10 19:58, Robert P. J. Day wrote:
    > >
    > > finally getting back to clawing my way thru the python 3 book so
    > > probably a number of newbie questions coming up. first one -- can i
    > > check if a module is importable (equivalently, exists on sys.path, i
    > > assume) without trying to import it first?
    > >
    > > i can see that i can use try/except and just run "import" -- is that
    > > the accepted way to test?

    >
    > check imp.find_module()


    thanks, that's what i was looking for. i'm sure i'll run across
    that shortly as i keep working my way thru this python 3 book.

    rday
    --

    ========================================================================
    Robert P. J. Day Waterloo, Ontario, CANADA

    Linux Consulting, Training and Kernel Pedantry.

    Web page: http://crashcourse.ca
    Twitter: http://twitter.com/rpjday
    ========================================================================
     
    Robert P. J. Day, Jan 20, 2010
    #3
    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. Val
    Replies:
    2
    Views:
    376
  2. Daniel Berger
    Replies:
    3
    Views:
    116
    Daniel Berger
    Oct 30, 2004
  3. Kevin Howe

    Ruby DL::Importable struct issue

    Kevin Howe, Nov 23, 2004, in forum: Ruby
    Replies:
    7
    Views:
    172
    Kevin Howe
    Nov 25, 2004
  4. Terry Reedy

    Building importable _tkinter on Windows

    Terry Reedy, Mar 10, 2013, in forum: Python
    Replies:
    0
    Views:
    156
    Terry Reedy
    Mar 10, 2013
  5. Terry Reedy
    Replies:
    0
    Views:
    107
    Terry Reedy
    Mar 10, 2013
Loading...

Share This Page