sys.prefix in COM

Sue Giller sag at hydrosphere.com
Tue Nov 27 15:58:10 EST 2001


Awhile ago I posted a question about why my path was changing 
when I use a python COM object from VB vs using the object from 
python.  Steve Holden replied that it looked like COM interface 
wasn't using site.py.

I have finally looked into this, and I wonder if there might be a 
problem in sys.prefix in COM.  I am a python wannabe, so I am not 
sure if the following is expected or what.

I created a simple COM object in python that returns the state of 
sys.prefix, and sys.path. 

def GetPath(self):
        import sys
        prefix = sys.prefix
        line = "Prefix: " + prefix + ":"
        for path in sys.path:
            path = path.replace("\n","")
            if path != "":
                line = line + "\n" + path
        return line

If I run a test case in python that makes the COM object using 
win32com.server.dispatch, it nicely prints out a good sys.prefix and 
a path.

   from win32com.client import Dispatch
   ds = Dispatch("PythonDemos.Utilities")
   p = ds.GetPath()
   print p

Prefix: C:\Python21:
C:\Python21\Pythonwin
etc.....

However, if I create the COM object in VB6, I get a blank string back 
for sys.prefix.

Set objTester = CreateObject("PythonDemos.Utilities")
results = objTester.GetPath
ss = "Results are " & results

Prefix: :
C:\Python21\scripts\com
etc.....

With the blank prefix, the path has dropped any items that are 
located via *.pth files in my base python directory, thus loosing 
things like Numeric that is installed in my c:\python21 directory.

I am unsure what exactly sys.prefix should be pointing to (I am 
assuming it is where my python 'stuff' is installed to; c:\python21 in 
my case), but I can't believe the string should be blank.

Does anyone have any insights into this?  I don't want to have to 
hardwire my base python directory into my various com objects to 
get them to find these other libraries, etc.  I have done that up to 
now, but I need to make these objects more general so they will 
work on any python site.

Thanks

sue




More information about the Python-list mailing list