help, installation, packaging, python, tutorial

Using py2exe the right way

Edit: I am developing a new blog in Python using Pelican. I have posted this post on that blog as well. Make sure that you visit that blog and offer any advice if you have.

Hi guys how are you? I hope all of you are fine. Recently I was working on a PyQt project. The project was youtube-dl-GUI. It is a GUI for the ever popular youtube-dl project. After writing all the code I decided to make an exe in order to ease the deployment of my project on windows. For this purpose I decided to use py2exe which suited besst to my needs. However it is necessary to know that py2exe is not the only Python to exe compiler out there. Some of the other popular Python exe makers out there are pyinstaller and cx_freeze.

These exe makers simply compile our script to bytecode and packages it with a Python execultable so that our program/script can work on those Windows’ PC’s which don’t have Python installed.

However during the exe making process I faced a couple of problems and there was not a single blogpost anywhere dedicated to solving all of those problems. In this post I will try to list all of those problems and will also list the solutions which I used to solve those problems.

MSVCP90.dll missing:

The first error which I came across was the MSVCP90.dll missing error. I searched on Google and came to know that I needed to install the Microsoft Visual C++ 2008 Redistributable Package in order to solve the problem. I came to know that it was already installed on my system but I still reinstalled it just to be sure. After reinstallation I tried to run py2exe again but the problem still persisted. After searching endlessly for an hour or so I came forward to a solution. The solution was to search and copy MSVCP90.dll from my system folder to Python’s DLL folder which in my case was C:\Python27\DLLs (it might be different on your system). I applied the solution and Voila it worked.

No module named sip:

Another error I came across while compiling a PyQt4 script was the ImportError: No module named sip error. This one was pretty easy to solve. The solution was located on py2exe website. One solution was to use py2exe like this:

python py2exe --includes sip

The content of the were as follows:

from py2exe.build_exe import py2exe
from distutils.core import setup
setup( console=[{"script": ""}] )

Another solution was to modify the file like this:

from distutils.core import setup
import py2exe
setup(windows=[{"script":""}], options={"py2exe":{"includes":["sip"]}})

And then run py2exe like this:

python py2exe

These solutions solved the problem for me.

No images displayed in PyQt:

This solution was again hard to find but however I was able to find it. The solution was to package the PyQt image plugins with the application. I added this in my file:

    data_files = DATA,

This solved the problem for me.

Making a single exe:

Previously I use innosetup to make an installer but later I came across another method which allowed me to use py2exe to directly create a bundled exe which could be run by double clicking. In order to achieve this I modified my file like this:

from distutils.core import setup
import py2exe, sys, os
    options = {'py2exe': {'bundle_files': 1, 'compressed': True,"includes":["sip"]}},

Please note that if you want to make an installer you need to use innosetup or an equivalent.


After making all those edits I ended up with something like this:

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



    options = {'py2exe': {'bundle_files': 1, 'compressed': True,"includes":["sip"]}},
    windows = [{'script': ""}],
    zipfile = None,
    data_files = DATA,

I hope this post allowed you to solve some of your py2exe problems. If you need any further help then comment below, shoot me an email or tweet it directly to me.


27 thoughts on “Using py2exe the right way

  1. Pingback: Python-digest #17. Новости, интересные проекты, статьи и интервью [2 марта 2014 — 9 марта 2014] | Вести3.ру — Информационный журнал

  2. Pingback: Python-digest #17. Новости, интересные проекты, статьи и интервью [2 марта 2014 — 9 марта 2014] » CreativLabs

  3. Jason Reed says:

    For some reason I’m still getting the Missing Sip error even though I’ve called for it in my script. I’m also running it in the command line as “python py2exe” but when I run the exe I still get that error. However, running the command “python py2exe –includes sip compiles the project just fine. The only problem: I’m missing more modules and don’t know how to list multiple modules other than in the file. Please help?

    • You can expand whats in the includes section for what ever missing modules error messages you are getting


  4. Pingback: Using py2exe the right way | Bite Sized Python Tips | TextMagic

  5. Pingback: [PyQt | py2exe] 製作GUI(PyQt)視窗應用程式的exe執行檔 | Eason's Garage

  6. Using PyQt4 / Python 3.4, and wanting a single executable (not a folder of files), I think that limits me to using py2exe instead of some of the other newbie-friendly gui-based tools (cx_freeze , pyInstaller, etc).

    Unfortunately, while my .py file runs fine when I execute it in tge IDLE GUI, it doesn’t run from the console due to ‘no module named xxxx’ errors.

    I assume I have to get that to work first before running py2exe… but what makes it work from the IDLE gui and not via a command prompt?

  7. hi there,
    i am trying to make a .exe file , i already had an partial success.
    i am using tkinter, matplotlib and numpy library´s.
    i tried a lot of variables ,but there is always an error.
    the most common is ”matplot file data not found”.
    have you ever had this problem? please, help me.

  8. Pierre Dimo says:

    Excellent synthesis of regular outcoming questions about py2exe. However, there is one missing : how to automatically add the *.ui files (PyQt generated ) to the dist directory, without converting them to a python file ? Is there any solution for this ?

  9. I’ve an icon associated with my app, but when i convert it to an exe the icon is not present. Any information on how I might include it?

    In the UI file the line is:
    icon.addPixmap(QtGui.QPixmap(_fromUtf8(“icons/favicon.ico”)), QtGui.QIcon.Normal, QtGui.QIcon.Off)

    So I’ve added icons/favicon.ico to the dist directory, but no joy.


    • Hey there! Thank you for replying. I am not so sure about what the problem might be because I have not worked with py2exe and windows recently. However, I do know that py2exe has a grudge with task-bar icons and even I had a hard time getting them to work properly.

  10. vishal says:

    Hi Yassob,

    I faced another problem where, when i click the exe file, it run rapidly and shuts, does not hold the window, looks like I am missing something during creation, can you guide.

  11. Tek Mailer says:

    Vishal, try ending your code in a raw_input….

    endRun = raw_input(r” “)

    or put your run in a “while” loop that can only escape with a flag of some sort.

  12. gilles says:

    Hi Yassob,
    You’re first point caught my eye as I ran into that a few years back. I had found a relatively good answer at “”

    In any case, adding ‘MSVCP90.dll’ to the excludes appears to have worked in my case.

    PY2EXE (or CXFreeze) all seem to be hit and miss at times and gathering from all the forum chatter, needs a lot of tweaking at time.
    Other issues I ran into: Ex. the vlc binding might not py2exe properly work depending on the and python versions you are trying, then furthermore it may or may not py2exe properly depending on the bundle option.
    Currently also having problems trying to py2exe an app that uses pysnmp (4.2.5 and/or 4.3) .

    Anyways I hope the posting on “wxpython-py2exe-app-not-bundling-properly” may help explain a few things.

  13. Kirk-In-Toronto says:

    Please help…

    C:\Python27\python.exe C:\Python27\projects\ py2exe

    Windows10 / Python27 / Tkinter —
    The following appear to be missing

    … and thanks

  14. Pingback: Deploying a PyQt app using py2exe

  15. Sergio Frayle Perez says:

    I have been using py2exe for some time and I too have had similar problems but I managed to solve them, but right now I am really stuck on one that I can’t fix. The thing is that I must use gnuradio.wxgui for the app I am currently developing, instead of PyQt which is what I have always used. For PyQt I include “PyQt4.QtGui” and “PyQt4.QtCore” in the because I always use these modules, without them a can’t build the exe. But now for the gnuradio.wxgui app I don’t know what happens that I manage to build the exe and when I run it, it shows up but it doesn’t respond, it just freezes, nothing happens and any click on the app causes it to close. I was wondering if there was any special module that must be included as in the PyQt case. If you happen to know what is causing this I would really appreciate your help.
    Thank you so much
    Sergio Frayle

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s