Newbie question about importing modules.

2010-12-16 Thread cronoklee
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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about importing modules.

2010-12-17 Thread cronoklee
Hey thanks for the help fellas. The links were helpful and the pyExe program 
looks great. I might well end up using this.

I'm still a little confused as to how the directory structure works. PIL 
(http://www.pythonware.com/products/pil/#pil117), for example comes packed in a 
folder called Imaging-1.1.7 which contains a bunch of other directories, one of 
which is PIL. Now, what I've done is move this subfolder PIL into the same 
directory as my python test script and used:
from PIL import Image
I assume this instructs python to look in the PIL folder for Image.py. Am I 
wrong? I feel like I'm wrong. If I need to put the whole Imaging-1.1.7 folder 
somewhere else, how do I reference the specific Image module that I need?

Sorry for the stupidity - I'm coming from PHP where you just include 
path/to/script.php so this is a bit alien to me.

Thanks a lot,
cronoklee
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about importing modules.

2010-12-22 Thread cronoklee
On Wed, Dec 22, 2010 at 7:57 PM, Tim Roberts  wrote:
cronoklee wrote:
>
> Thanks Tim - You've certainly shed some light. I presume the PIL
> installer is setup.py and installation is simple a case of running it?

Yes:
   python setup.py install

That scheme is called "distutils".  Since it became part of the standard
Python distribution many years ago, it is now ubiquitous.

> Is this usually the case for python 'source distribution' packages?

Yes.  In the Linux world, with a few exceptions, EVERY Python add-on
package is installed that way.  In the Windows world, most smaller
packages come that way.  Larger packages will have an MSI installer that
does essentially the same thing.

Once in a while, you'll download a script that consists only of a single
file.  That would really be the only exception.

> Is there a term for packages that do not need to be installed? This
> might help me search for them in future.

I don't think that's the right answer.  The installation process is
rarely more complicated than copying files to the site-packages
directory of your current Python version.  The installer can verify
dependencies and make sure everything is OK.  It's a Good Thing.

--
Tim Roberts




Thanks a lot Tim - all makes sense. I appreciate the lesson!
cronoklee
-- 
http://mail.python.org/mailman/listinfo/python-list