import via pathname

Thomas Guettler guettli at thomas-guettler.de
Mon Jun 20 09:44:24 EDT 2005


Am Mon, 20 Jun 2005 06:31:38 -0700 schrieb passion_to_be_free:

> Okay, so in my li'l python script I'm importing a few 3rd party modules
> that I have installed on my comp.  I need to distribute this script to
> several other people, but I won't have access to install the modules on
> their comp's.  I'm thinking I'll include these modules with my script
> and deliver them as a bundle. When I write my script, is there a way to
> declare the import statements and specify a relative path to where the
> modules are located?

Hi,

You can change sys.path at runtime. Example:

libdir=os.path.join(os.environ["HOME"], "mylibs")
assert(os.path.exists(libdir))
sys.path.insert(0, libdir)

import mylibrary # $HOME/mylib/mylibrary.py

HTH,
 Thomas

-- 
Thomas Güttler, http://www.thomas-guettler.de/





More information about the Python-list mailing list