views:

575

answers:

1

I can't make py2exe to pack correctly even a simple script that uses win32file I'm constantly getting the following error message:

Traceback (most recent call last):
  File "dependency_checker.py", line 1, in <module>
  File "win32file.pyc", line 12, in <module>
  File "win32file.pyc", line 10, in __load
ImportError: DLL load failed: The specified procedure could not be found.

The script looks as follows:

import win32file
print "Hello world!"

And here is the setup.py:

from distutils.core import setup
import py2exe
setup(console=['dependency_checker.py'])

Have you had similar problem before?

Versions:

Python 2.6.2, py2exe 0.6.9, pywin32-214, Windows 7 and Windows XP Pro as target machine

UPDATE:

  • I can run the bundled program on my windows 7 where it was created but I can't run it on the XP machine.
  • The part of win32file.pyc that throws the error looks as follows:

    >>> imp.load_dynamic('win32file', r'C:\test\setup-test\src\dist\win32file.pyd')
    

The line above on my dev box (windows 7) runs correctly while on test box (windows XP) returns the error.

** UPDATE 2: **

When I use imp.load_dynamic to load win32file form python installation then I can reload the win32file.pyd for the dist folder without the error.

+1  A: 

The soution was to remove MSWSOCK.dll that was copied to the dist directory by py2exe incorrectly.

I've used procmon and listdll to check what is loaded by win32file.pyd when import is successfull and what dll are loaded when import fails. Then having the list of dlls I've checked if they are loaded correctly ie. python dlls from dist folder and windows dlls from windows folder.

Here is the setup.py that works fine

from distutils.core import setup
import py2exe
setup(console=['dependency_checker.py'],
     options={'py2exe': {"dll_excludes": ["mswsock.dll", "MSWSOCK.dll"]}}
     )
Piotr Czapla