4
votes

I'm trying to use py2exe and right now I'm just having trouble building the samples and tutorials that come with py2exe. I run setup.py and that goes fine but when I try to run the exe that is created I get the "LoadLibrary(pythondll) failed" error. I haven't moved the exe from the dist directory and I see that python27.dll is in that dist directory. Does anyone know what might be happening?

In case it matters I'm running 32 bit python 2.7 with the corresponding 32 bit python 2.7 py2exe on windows 7.

Thanks

The test.py file just contains print "test"

Here's my setup.py based off what Kirk wrote:

from distutils.core import setup
import py2exe
import sys
from glob import glob

project_folder = r'C:\\Python27\\Lib\site-packages\\py2exe\\samples\\test\\'
data_files = [
        ("dlls", glob(project_folder + r'dlls\\*.dll'))                  
        ,("pyds", glob(project_folder + r'pyds\\*.pyd'))  
         ]
options = { }

setup(
name='test'
,options = options
,zipfile = None
,data_files=data_files
,console=['test.py']
)
2

2 Answers

1
votes

You'll want to specifically include the python27.dll file. If you're including multiple things, use glob and a data files array like below to get the best results with py2exe. For this example, create a Dll folder and put python27.dll in there.

from distutils.core import setup
import py2exe
import sys
from glob import glob
data_files = [
        ("Stuff", glob(r'C:\projectfolder\Stuff\*.*')) 
        ,("dlls", glob(r'C:\projectfolder\dlls\*.dll'))                  
        ,("pyds", glob(r'C:\projectfolder\pyds\*.pyd'))  
         ]
options = { }

setup(
name='ProjectName'
,options = options
,zipfile = None
,data_files=data_files
,console=['projectname.py']
)
1
votes

I know this is a pretty old question, but I had a similar problem. I had uninstalled python and py2exe 64 bit to replace it with the 32 bit version. After I did this, I always got this error. Later, I deleted my dist and build directories from my project, and the subsequent build worked.