Windows .executable from Python developing in Ubuntu

Puhh…that is a tricky one! After fiddling a lot it…it seems now so easy…

So I think I have to share that with…everybody who ever is also faced with that strange task 😉

OK…I think you already know that it is not simply possible to make an executable file for a Windows system…with the well know extension: *.exe

But we will make that magic happen 😉 … in fact it is not magic its just a combination of the following tools/versions:

Quick overview:

We will make an executable file from our python-project using pyinstaller. We do that in a simulated windows-environment using wine. This, lets call it, ‘simulated windows’ gets an installation of python and pywin32. As it is always a good idea to work clean…we do that in a virtual environment, so our major wine-installation wond’t get touched…isn’t that cool 🙂 Let’s do it:

Make a test project

Actually, we could make a very simple example like:

mkdir ~/pyToExe
cd ~/pyToExe

print "Hello, this is a test!"

But I a very good tutorial gave some more complex code that worked directly, so we’ll use that:

import Tkinter
from Tkinter import *
root = Tk()
root.title('A Tk Application')
Label(text='I am a label').pack(pady=15)
print "Successfully, saved processed!'"


Install ‘pyinstaller’

As we can read in the same tutorial, but also here, we can simply make a single execeutable file doing that:

git clone
python pyinstaller/

Check it out…you can already execute it!


Setup a simple ‘virtual windows’

But try that on windows…you will fail! As this is made with Linux it is not executable on windows! I searched a lot for that ‘cross-compiling’ problem and found finally two very good links:

And found out that the guy, who gave the solutions (BTW: Thank you very much!!!) implemented a solution to start wine in a virtual environment. Let’s initialise it:

git clone
apt-get install scons
./virtual-wine/vwine-setup venv_wine

At the end you can choose the type of Windows…I chose Windows7!

Upgrade to a ‘virtual windows-python’

  • we can start the new virtual wine-environment (pretty similar to an normal virtualenv), and
  • install python and pywin32 (which we have dowloaded from the links above and saved in our folder ‘pyToExe’, in the the meantime 🙂

(Helpfull, but I do it differently)

. venv_wine/bin/activate
wine msiexec -i python-2.7.8.msi
wine pywin32-218.win32-py2.7.exe

At this point it is very necessary to use versions that fit exactly to each other!

Make a real .exe*cutable

Now, we have a simple virtual ‘windows-python’ which we can give pyinstall as python-environment:

rm -r build
rm -r dist
rm test.spec
wine c:/Python27/python.exe pyinstaller/ --onefile
ll dist/

Yeah…there is the needed extension, but see test if it works in windows using wine:

wine dist/test.exe

What did I say simple isn’t it?!? Go on and try it on a windows…my test where successfull 🙂

All still open tabs of my browser in one list, thank you so much!!!

Make following changes to remove warnings :-

  1. Go to C:\Python27\Lib\site-packages\PyInstaller\
  2. Find the def append(self, tpl): function.
  3. Change if tpl[2] == "BINARY": to if tpl[2] in ["BINARY", "DATA"]:

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