pythoncom -- ImportError: DLL load failed

R

Richard Whidden

I've sniffed around for a solution to this problem but I can't find
anything.

The simple COM example in the "Programming on Win32" O'Reilly book works
fine. However, as soon as I add 'import pgdb' to the object, chaos ensues
promply.

Here's what I did.

Step 1, write this:
foo.py ------
# print pythoncom.CreateGuid()
import pgdb
class PythonUtilities:
_public_methods_ = [ 'SplitString']
_reg_progid_ = "FooFoo.Utilities"
_reg_clsid_ = "<Run pythoncom.CreateGuid() from a python prompt and insert
value here."

def SplitString(self, val, item=None):
import string
if item !=None: item = str(item)
return string.split(str(val), item)

if __name__=='__main__':
print "Registering COM server"
import win32com.server.register
win32com.server.register.UseCommandLine(PythonUtilities)
----- End of foo.py

Step 2, run 'python foo.py'.

Step 3, write this:
test.vbs -----
set o = CreateObject("FooFoo.Utilities")
------- End of test.vbs

Step 4, run 'cscript /nologo test.vbs'

Step 5, watch it fail.

Error ----------
C:\devel\blip\test.vbs(1, 1) (null): Unspecified error

pythoncom error: ERROR: server.policy could not create an instance.

Traceback (most recent call last):
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 136,
in CreateInstance
return retObj._CreateInstance_(clsid, reqIID)
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 194,
in _CreateInstance_
myob = call_func(classSpec)
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 727,
in call_func
return resolve_func(spec)(*args)
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 716,
in resolve_func
module = _import_module(mname)
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 735,
in _import_module
__import__(mname)
File "C:\devel\blip\foo.py", line 4, in <module>
class PythonUtilities:
File "C:\devel\blip\foo.py", line 5, in PythonUtilities
import pgdb
File "C:\Python26\Lib\site-packages\pgdb.py", line 66, in <module>
from _pg import *
ImportError: DLL load failed: The specified module could not be found.
pythoncom error: Unexpected gateway error

Traceback (most recent call last):
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 136,
in CreateInstance
return retObj._CreateInstance_(clsid, reqIID)
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 194,
in _CreateInstance_
myob = call_func(classSpec)
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 727,
in call_func
return resolve_func(spec)(*args)
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 716,
in resolve_func
module = _import_module(mname)
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 735,
in _import_module
__import__(mname)
File "C:\devel\blip\foo.py", line 4, in <module>
class PythonUtilities:
File "C:\devel\blip\foo.py", line 5, in PythonUtilities
import pgdb
File "C:\Python26\Lib\site-packages\pgdb.py", line 66, in <module>
from _pg import *
ImportError: DLL load failed: The specified module could not be found.
pythoncom error: CPyFactory::CreateInstance failed to create instance.
(80004005)
--------- End of Error

I've tried a few things. If I import foo.py into a python script, it works
fine. It only fails if I try things via COM.

I've run depends.exe. Everything can see everything else.

I've moved libpq.dll to \windows\system32, \scriptpath, \postgres\lib,
\postgres\bin... Probably other places too to no avail.

I'm sure I've tried other things, I just can't think of them right now. I
have this sickening feeling in my gut that the solution is so obvious that a
blind and dead person would have spotted the solution before me.

Anyway, if anyone has an idea (or a link to an idea) please let me know.

Thanks,
Richard Whidden
 
R

Richard Whidden

By including the following DLLs on a Windows 2000 image I have running
Python 2.5, my little sample app works...
comerr32.dll krb5_32.dll libintl-8.dll python26.dll
gssapi32.dll libeay32.dll libpq.dll ssleay32.dll
k5sprt32.dll libiconv-2.dll python25.dll
msvcm90.dll msvcp90.dll msvcr90.dll

However, on my WinXP development machine (running Python 2.6) this doesn't
work--Instead I receive a message,
"An application has made an attempt to load the C runtime library
incorrectly..." Once I remove the msvc* files, it goes back to the original
problem...

Argh.

The msvc* dlls are in an odd place:
C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_6f74963e

I've tried including that directory to my system path too, of course.



Richard Whidden said:
I've sniffed around for a solution to this problem but I can't find
anything.

The simple COM example in the "Programming on Win32" O'Reilly book works
fine. However, as soon as I add 'import pgdb' to the object, chaos ensues
promply.

Here's what I did.

Step 1, write this:
foo.py ------
# print pythoncom.CreateGuid()
import pgdb
class PythonUtilities:
_public_methods_ = [ 'SplitString']
_reg_progid_ = "FooFoo.Utilities"
_reg_clsid_ = "<Run pythoncom.CreateGuid() from a python prompt and
insert value here."

def SplitString(self, val, item=None):
import string
if item !=None: item = str(item)
return string.split(str(val), item)

if __name__=='__main__':
print "Registering COM server"
import win32com.server.register
win32com.server.register.UseCommandLine(PythonUtilities)
----- End of foo.py

Step 2, run 'python foo.py'.

Step 3, write this:
test.vbs -----
set o = CreateObject("FooFoo.Utilities")
------- End of test.vbs

Step 4, run 'cscript /nologo test.vbs'

Step 5, watch it fail.

Error ----------
C:\devel\blip\test.vbs(1, 1) (null): Unspecified error

pythoncom error: ERROR: server.policy could not create an instance.

Traceback (most recent call last):
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 136,
in CreateInstance
return retObj._CreateInstance_(clsid, reqIID)
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 194,
in _CreateInstance_
myob = call_func(classSpec)
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 727,
in call_func
return resolve_func(spec)(*args)
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 716,
in resolve_func
module = _import_module(mname)
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 735,
in _import_module
__import__(mname)
File "C:\devel\blip\foo.py", line 4, in <module>
class PythonUtilities:
File "C:\devel\blip\foo.py", line 5, in PythonUtilities
import pgdb
File "C:\Python26\Lib\site-packages\pgdb.py", line 66, in <module>
from _pg import *
ImportError: DLL load failed: The specified module could not be found.
pythoncom error: Unexpected gateway error

Traceback (most recent call last):
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 136,
in CreateInstance
return retObj._CreateInstance_(clsid, reqIID)
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 194,
in _CreateInstance_
myob = call_func(classSpec)
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 727,
in call_func
return resolve_func(spec)(*args)
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 716,
in resolve_func
module = _import_module(mname)
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 735,
in _import_module
__import__(mname)
File "C:\devel\blip\foo.py", line 4, in <module>
class PythonUtilities:
File "C:\devel\blip\foo.py", line 5, in PythonUtilities
import pgdb
File "C:\Python26\Lib\site-packages\pgdb.py", line 66, in <module>
from _pg import *
ImportError: DLL load failed: The specified module could not be found.
pythoncom error: CPyFactory::CreateInstance failed to create instance.
(80004005)
--------- End of Error

I've tried a few things. If I import foo.py into a python script, it
works fine. It only fails if I try things via COM.

I've run depends.exe. Everything can see everything else.

I've moved libpq.dll to \windows\system32, \scriptpath, \postgres\lib,
\postgres\bin... Probably other places too to no avail.

I'm sure I've tried other things, I just can't think of them right now. I
have this sickening feeling in my gut that the solution is so obvious that
a blind and dead person would have spotted the solution before me.

Anyway, if anyone has an idea (or a link to an idea) please let me know.

Thanks,
Richard Whidden
 
R

Richard Whidden

I installed a clean copy of Python 2.5, pywin32 and PyGreSQL and it works.
I'll have to figure out what broke with my 2.6 install.

Thanks for letting me scribble here.

Richard Whidden said:
I've sniffed around for a solution to this problem but I can't find
anything.

The simple COM example in the "Programming on Win32" O'Reilly book works
fine. However, as soon as I add 'import pgdb' to the object, chaos ensues
promply.

Here's what I did.

Step 1, write this:
foo.py ------
# print pythoncom.CreateGuid()
import pgdb
class PythonUtilities:
_public_methods_ = [ 'SplitString']
_reg_progid_ = "FooFoo.Utilities"
_reg_clsid_ = "<Run pythoncom.CreateGuid() from a python prompt and
insert value here."

def SplitString(self, val, item=None):
import string
if item !=None: item = str(item)
return string.split(str(val), item)

if __name__=='__main__':
print "Registering COM server"
import win32com.server.register
win32com.server.register.UseCommandLine(PythonUtilities)
----- End of foo.py

Step 2, run 'python foo.py'.

Step 3, write this:
test.vbs -----
set o = CreateObject("FooFoo.Utilities")
------- End of test.vbs

Step 4, run 'cscript /nologo test.vbs'

Step 5, watch it fail.

Error ----------
C:\devel\blip\test.vbs(1, 1) (null): Unspecified error

pythoncom error: ERROR: server.policy could not create an instance.

Traceback (most recent call last):
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 136,
in CreateInstance
return retObj._CreateInstance_(clsid, reqIID)
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 194,
in _CreateInstance_
myob = call_func(classSpec)
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 727,
in call_func
return resolve_func(spec)(*args)
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 716,
in resolve_func
module = _import_module(mname)
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 735,
in _import_module
__import__(mname)
File "C:\devel\blip\foo.py", line 4, in <module>
class PythonUtilities:
File "C:\devel\blip\foo.py", line 5, in PythonUtilities
import pgdb
File "C:\Python26\Lib\site-packages\pgdb.py", line 66, in <module>
from _pg import *
ImportError: DLL load failed: The specified module could not be found.
pythoncom error: Unexpected gateway error

Traceback (most recent call last):
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 136,
in CreateInstance
return retObj._CreateInstance_(clsid, reqIID)
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 194,
in _CreateInstance_
myob = call_func(classSpec)
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 727,
in call_func
return resolve_func(spec)(*args)
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 716,
in resolve_func
module = _import_module(mname)
File "C:\Python26\lib\site-packages\win32com\server\policy.py", line 735,
in _import_module
__import__(mname)
File "C:\devel\blip\foo.py", line 4, in <module>
class PythonUtilities:
File "C:\devel\blip\foo.py", line 5, in PythonUtilities
import pgdb
File "C:\Python26\Lib\site-packages\pgdb.py", line 66, in <module>
from _pg import *
ImportError: DLL load failed: The specified module could not be found.
pythoncom error: CPyFactory::CreateInstance failed to create instance.
(80004005)
--------- End of Error

I've tried a few things. If I import foo.py into a python script, it
works fine. It only fails if I try things via COM.

I've run depends.exe. Everything can see everything else.

I've moved libpq.dll to \windows\system32, \scriptpath, \postgres\lib,
\postgres\bin... Probably other places too to no avail.

I'm sure I've tried other things, I just can't think of them right now. I
have this sickening feeling in my gut that the solution is so obvious that
a blind and dead person would have spotted the solution before me.

Anyway, if anyone has an idea (or a link to an idea) please let me know.

Thanks,
Richard Whidden
 
M

Mark Hammond

Richard said:
I installed a clean copy of Python 2.5, pywin32 and PyGreSQL and it works.
I'll have to figure out what broke with my 2.6 install.

Make sure you have 2.6.2

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top