sys.prefix in COM
Gordon McMillan
gmcm at hypernet.com
Tue Nov 27 16:51:39 EST 2001
Sue Giller wrote:
[...]
> 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.
[...]
> 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.
[...]
> However, if I create the COM object in VB6, I get a blank string back
> for sys.prefix.
> 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.
Excellent detective work.
> 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.
There is a reason for this. sys.prefix is really only meaningful on *nix. On
Windows it is usually taken (correctly) to mean "where the executable is".
site.py & friends can be picked up from there.
If you registered your COM objects as CLSCTX_LOCAL_SERVER you would indeed
have a sys.prefix. But if it's inprocess, the executable isn't Python. In
fact, pythoncomXX.dll loaded pythonXX.dll for you, and without knowing where
their python.exe lives, they're lost. Well, only a little.
I've never encountered this problem, but I'd guess you could tweak Python's
registry entries to get around this.
-- Gordon
http://www.mcmillan-inc.com/
More information about the Python-list
mailing list