Skip to content

Windows .exe*cutable from Python developing in Ubuntu

19. July 2014

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
nano test.py


# test.py
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:


# test.py
import Tkinter
from Tkinter import *
root = Tk()
root.title('A Tk Application')
Label(text='I am a label').pack(pady=15)
root.mainloop()
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 https://github.com/pyinstaller/pyinstaller
python pyinstaller/pyinstaller.py test.py

Check it out…you can already execute it!

./dist/test

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 https://github.com/htgoebel/virtual-wine.git
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/pyinstaller.py --onefile test.py
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!!!

Advertisements
6 Comments
  1. Excellent! This is what blogs should be for. Share your experiences in solving a problem to bootstrap everyone else’s productivity. This was very helpful for me. Thank you.

  2. Nice article, but I met the problem that it shows up an error, “No module named pkg_resources , if your version of pyinstaller is greater than 2.1

Trackbacks & Pingbacks

  1. python bpoject building with pyinstaller | 我爱源码网
  2. Cross-compiling with pyinstaller | stellansostlund
  3. Pyinstaller in Wine leads to: ImportError: No module named pkg_resources - ubuntutextbook

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: