From: spamfranke at bigfoot.de (Stefan Franke)
Date: Sat, 17 Apr 1999 17:27:52 GMT
Subject: sys.path.insert - how to make it global?
References: <19990416172011.A1551755@vislab.epa.gov> <3718a8aa.4229211@news.omnilink.de> <19990417113121.A1627033@vislab.epa.gov>
Message-ID: <3718c0a3.10366776@news.omnilink.de>
Content-Length: 1705
X-UID: 1361                                                  

In that case the problem seems to be somewhere else. Can
you post the traceback, your directory layout and perhaps
some isolated code?

Your code snippet says :
  # Augment search path to pull in our C library wrappers

Maybe importing C extensions makes your program fail?


The following example should resemble your situation (let
me know if it doesn't):

-------- file a.py in some_directory

# First, you can't import c
try:
    import c
except ImportError:
    print "import c failed"

# Patch sys.path
import sys
sys.path.append ("new_directory")

# b imports c with the new path
import b

-------- file b.py in some_directory

import sys
print sys.path

import c

-------- file c.py in some_directory/new_directory

print "This is c"

---------------------------

When I run this from the Python console it prints:

Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import a
import c failed
['', 'D:\\Programme\\Python', 'D:\\Programme\\Pythonwin', 'D:\\Programme\\Python
  [... long path snipped...]
me\\Python\\lib\\plat-win', 'D:\\Programme\\Python\\lib\\lib-tk', 'D:\\Programme
\\Python', 'D:\\Programme\\Python\\lib\\site-python', 'new_directory']
This is c


Stefan

 * * *

On Sat, 17 Apr 1999 15:31:21 GMT, Randall Hopper <aa8vb at vislab.epa.gov> wrote:

>I'd already tried that.  It's effect doesn't appear to be global:
>
>   # Augment search path to pull in our C library wrappers
>   sys.path.insert( 0, '/home/mylogin/Wrappers' )
>
>   import MapFile
>
>This allows Python to find MapFile, but this doesn't allow MapFile to
>import other modules in that same Wrappers directory.
>
>Randall
>





