Wednesday, July 28, 2010

Error: pywintypes.py DLL load failed

Some of my wxpython routines that used to work, stopped working. The error message was:

Traceback (most recent call last):
File "boot_com_servers.py", line 21, in
File "c:\python25\lib\site-packages\pythoncom.py", line 3, in
pywintypes.__import_pywin32_system_module__("pythoncom", globals())
File "C:\Python25\lib\site-packages\win32\lib\pywintypes.py", line 100, in __import_pywin32_system_module__
('.dll', 'rb', imp.C_EXTENSION))
ImportError: DLL load failed: The specified procedure could not be found.

If you look at pywintypes.py, you will see that it is a major hack that goes through all sorts of contortions to find the dlls. Here are some of the comments:

# This has been through a number of iterations. The problem: how to
# locate pywintypesXX.dll when it may be in a number of places, and how
# to avoid ever loading it twice. This problem is compounded by the
# fact that the "right" way to do this requires win32api, but this
# itself requires pywintypesXX.
# And the killer problem is that someone may have done 'import win32api'
# before this code is called. In that case Windows will have already
# loaded pywintypesXX as part of loading win32api - but by the time
# we get here, we may locate a different one. This appears to work, but
# then starts raising bizarre TypeErrors complaining that something
# is not a pywintypes type when it clearly is!

My hat is off to those that had the patience to deal with this BS.

The DLLs in question are:
  • pythoncom25.dll
  • pywintypes25.dll
Anyway - I added a few print statements to pywintypes.py and found that it was trying to load the dll from my recent installation of TortoiseHg. Those DLLs were in the TortoiseHg folder, but they were version 2.5.212.0. The version of those files in my python installation was 2.5.210.0. I checked the win32 download site and they are at version 2.5.214.0.

I was hoping this problem would be solved in the new version, so I installed it. That updated the DLLs in C:\WINDOWS\system32 and C:\Python25\Lib\site-packages\pywin32_system32 but the problem remained.

I tried deleting all the python related DLLs in TortoiseHg. This created a new error:

Traceback (most recent call last):
File "boot_com_servers.py", line 21, in
File "C:\Python25\lib\site-packages\pythoncom.py", line 2, in
import pywintypes
File "C:\Python25\lib\site-packages\win32\lib\pywintypes.py", line 124, in
__import_pywin32_system_module__("pywintypes", globals())
File "C:\Python25\lib\site-packages\win32\lib\pywintypes.py", line 61, in __import_pywin32_system_module__
raise ImportError("Module '%s' isn't in frozen sys.path %s" % (modname, sys.path))
ImportError: Module 'pywintypes' isn't in frozen sys.path

If TortoiseHg messes with the python DLL's then it probably causes lots of problems with other python programs. A quick google search shows that TortoiseHg also messes up PyScripter. It seems that problem can be eliminated by upgrading TortoiseHg to 0.8 or higher.

"The incompatibility between PyScripter and the TortoiseHg Mercurial addon has finally been fixed with the release of TortoiseHg 0.8, which replaces the Python Windows shell extensions with C++ based ones"

I am using TortoiseHg 0.7.6. The current version is 1.1.1. Since I almost never use TortoiseHg, I decided to uninstall it. Uninstalling it made the problem go away. Hopefully by the time I need to reinstall TortoiseHg, these problems will all be worked out.

***Update Nov 11,2010***
I have started using Hg again. This time it is for my own project. I like it much better than SVN. I reinstalled TortoiseHg 1.1.2. The problems described above did not reappear.

No comments:

Post a Comment