Newbie question about importing modules.
Tim Roberts
timr at probo.com
Fri Dec 17 03:59:34 EST 2010
cronoklee <cronoklee at gmail.com> wrote:
>
>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.
That's not really true.
>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?
Absolutely.
>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?
PIL requires DLLs as well as other Python files. You can't just copy the
top-level PIL files to your own private directory.
>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?
If you are delivering a program to clients, then you should look at
something like py2exe, which will examine your code and produce a zip file
that includes all of the files your application will need.
If you are delivering a script for someone that will definitely have Python
installed, then you just need to identify the dependencies. Let that
person install PIL.
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list
mailing list