Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Newbie question about importing modules.

Reply
Thread Tools

Newbie question about importing modules.

 
 
cronoklee
Guest
Posts: n/a
 
      12-17-2010
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
 
Reply With Quote
 
 
 
 
shearichard
Guest
Posts: n/a
 
      12-17-2010
On Dec 17, 4:42*pm, cronoklee <(E-Mail Removed)> 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_ori...g_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/pi...book/image.htm


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

regards

Richard.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to keep a module with the same name as a module it is importing from importing itself? plb Python 2 02-08-2005 03:14 PM
Importing database: newbie issue Angelo Secchi Python 1 01-22-2004 03:39 PM
Newbie question: importing module from C nick Python 0 11-28-2003 04:41 AM
newbie - help - where do u store custom classes when importing namespaces in ASP ravi sankar ASP .Net 2 08-27-2003 10:39 AM
Importing packages and classes help required by newbie Rogue 9 Python 0 07-04-2003 09:00 PM



Advertisments