1
votes

I recently started experimenting with cython and py2exe to see if I can convert some of my python projects into standalone windows binaries. So far, I've had much success converting my pure python code into an exe containing all my custom python libraries using the zipfile=None option. The "dist" directory generated by py2exe is pretty clean, with all my libraries being embedded straight in the exe.

However, I'm having a bit of a problem after converting my libraries into .pyd files using Cython. When I create a new executable with the .pyd files instead of my original .py files, py2exe refuses to include the .pyd files in the executable and places them outside in the exe's directory instead. The libraries are the exact same ones as before, only compiled into .pyd form.

Here is my py2exe setup.py

from distutils.core import setup
import glob
import py2exe

setup_dict = dict(
    windows=[
        {
            "script": "myscript.py",
            "icon_resources": [(1, "myicon.ico")]
        }
    ],
    data_files=[
        ("folder1", ["folder1/file1", "folder1/file2"]),
        ("folder2", ["folder2/file1", "folder2/file2"])
    ],
    options = {
        "py2exe":{
            "includes": ['mylibrary1, 'mylibrary2', 'mylibrary3'],
            "excludes": ['excludedlib1', 'excludedlib2'],
            "dll_excludes": ['crypt32.dll']
        }
    },
    zipfile = None
)

# have to call it twice in order to workaround icon bug
setup(**setup_dict)
setup(**setup_dict)

Is there no way to include the .pyd's in my executable to avoid cluttering the directory? This was not a problem with the pure python version of the libraries.

If there is a way to include them, please let me know.

Also please note I am running 64-bit windows, I cannot use the "bundle files" option of py2exe as it only works on 32 bit systems.

I'm pretty sure it won't work. I think py2exe relies on the standard ability to import from zip files, which does not work with compiled modules: docs.python.org/2/library/zipimport.htmlDavidW