py2exe can't find msvcp90.dll

bythenumbers picture bythenumbers · Feb 11, 2013 · Viewed 10.4k times · Source

I'm working on converting a simple GUI script written with Python 2.7 and Pyqt4 into a standalone executable using py2exe. I keep getting "no such file exists" errors, and I've managed to fix a few, though this one seems stubborn. It can't find msvcp90.dll, and returns an error message with a short traceback to distutils and then back to my py2exe script, which isn't very enlightening. I've installed the MS C++ redistributable runtime, as recommended in

py2exe fails to generate an executable

but my script still can't locate the .dll. Below is my py2exe script, with the name of my script blocked out:

from distutils.core import setup
from py2exe.build_exe import py2exe
import sys, os, zmq

sys.argv.append('py2exe')

os.environ["PATH"] = \
os.environ["PATH"] + \
os.path.pathsep + os.path.split(zmq.__file__)[0]

setup(
    options = {'py2exe':{'bundle_files':1,"includes":["zmq.utils", 
            "zmq.utils.jsonapi","zmq.utils.strtypes"]}},
    console = [{'script':"#######.py"}],
    zipfile = None
)

I've already fixed an issue with zmq (which isn't ever used by my script, or my GUI, for that matter, as far as I know). What am I doing wrong?

Answer

dja picture dja · Feb 24, 2013

Right, I've managed to get my app to build, and although the question is now moderately old, it's my hope this is eventually of use to someone.

Firstly, py2exe is probably the wrong tool. It's old and AFAICT unmaintained. Consider PyInstaller instead. Using PyInstaller is literally as simple as installing it, installing PyWin32, and then going python %path_to_pyinstaller%/pyinstaller.py --onefile --windowed source.py. PyInstaller deals with all the mess of side by side assemblies and so on without you having to do anything.

In short, use PyInstaller.

However, to answer your question, this worked for me:

  1. The question you've linked to - in particular this answer is the right start. Find the right DLLs and copy them to C:\Python27\DLLs
  2. Ditch your existing setup.py file. If you're not using zmq, there's no reason to import it. Also, for a windowed application you want windows= not console=. My file goes (for packaging show.py):

    #!/usr/bin/python
    
    from distutils.core import setup
    import py2exe
    
    setup(options={'py2exe':{'bundle_files':1}},
          windows=['show.py'])
    

    (This is pinched off http://www.blog.pythonlibrary.org/2010/07/31/a-py2exe-tutorial-build-a-binary-series/)