ImportError depending on the calling module

Gabriel Genellina gagsl-py2 at
Thu Sep 6 18:44:16 CEST 2007

On 6 sep, 13:13, Samuel <knipk... at> wrote:
> On Sep 6, 5:44 pm, Gabriel Genellina <gagsl-... at> wrote:

> > They should import the package as any other
> > client code, without doing any import tricks nor playing with
> > sys.path.
> Why does it matter whether I install it in sys.path or whether
> sys.path is modified? What's the difference?

Because it's more simple, less error prone, easier to test, more

> What I am doing is I ship two modules in one tarball with my software.
> The software is only unpacked and ran. It has to work without
> installation.

That's fine, and a good requirement. Place inside the
container directory, and your package beneath it. Then you don't have
to modify sys.path to find the package - "import packagename" just
works. And it still works if the user installs the package (into site-
packages, by example).
 |-- foo/

Packages are... well, packages, boxes. Don't try to import a module
inside a package as it were a standalone module - relative imports
won't work then.
This was discussed some time ago <

Gabriel Genellina

More information about the Python-list mailing list