Newbie question about importing modules.

Discussion in 'Python' started by cronoklee, Dec 17, 2010.

  1. cronoklee

    cronoklee Guest

    Hi
    I'm starting my first python project but I'm having trouble getting
    off the ground.
    I've read all I can find about relative and absolute import paths but
    it's just not making sense to me... There seems to be around ten
    different ways to import a script.

    I need my project to be portable so I can copy the whole folder to run
    on any PC that has python installed. Is it always possible to simply
    include modules in the project directory and reference them without
    installing into the main python directory? I've managed this with
    small classes through trial and error but when I try it with anything
    larger (like PIL module for example) I get errors. Do I need to
    actually install anything or is it enough just to include the relevant
    scripts?

    All the modules I've found come with tonnes of files and
    subdirectories. Do I need all these files or should I just choose the
    scripts/folders I need?

    Thanks,
    cronoklee
    cronoklee, Dec 17, 2010
    #1
    1. Advertising

  2. cronoklee

    shearichard Guest

    On Dec 17, 4:42 pm, cronoklee <> wrote:
    > Hi
    > I'm starting my first python project but I'm having trouble getting
    > off the ground.
    > I've read all I can find about relative and absolute import paths but
    > it's just not making sense to me... There seems to be around ten
    > different ways to import a script.
    >
    > I need my project to be portable so I can copy the whole folder to run
    > on any PC that has python installed. Is it always possible to simply
    > include modules in the project directory and reference them without
    > installing into the main python directory? I've managed this with
    > small classes through trial and error but when I try it with anything
    > larger (like PIL module for example) I get errors. Do I need to
    > actually install anything or is it enough just to include the relevant
    > scripts?
    >
    > All the modules I've found come with tonnes of files and
    > subdirectories. Do I need all these files or should I just choose the
    > scripts/folders I need?
    >
    > Thanks,
    > cronoklee


    You may find this useful as an overview of importing ...

    http://effbot.org/zone/import-confusion.htm

    .... also this ...

    http://diveintopython.org/object_oriented_framework/importing_modules.html

    I may be stating the obvious but here's an example of using the Image
    object offered by PIL ...

    from PIL import Image

    .... as documented here ...

    http://www.pythonware.com/library/pil/handbook/image.htm


    Regarding bundling PIL with an app I'd second what Tim Roberts has to
    say regarding py2Exe

    regards

    Richard.
    shearichard, Dec 17, 2010
    #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. Tobiah
    Replies:
    2
    Views:
    310
    Tobiah
    Sep 14, 2003
  2. pythos
    Replies:
    3
    Views:
    334
    Jeremy Bowers
    Aug 22, 2004
  3. plb
    Replies:
    2
    Views:
    346
  4. warhero

    importing modules question

    warhero, Oct 18, 2007, in forum: Python
    Replies:
    2
    Views:
    287
    Amit Khemka
    Oct 18, 2007
  5. Peter Peyman Puk

    Importing v reloading modules modules

    Peter Peyman Puk, Mar 19, 2010, in forum: Python
    Replies:
    0
    Views:
    296
    Peter Peyman Puk
    Mar 19, 2010
Loading...

Share This Page