Linux tools on Windows with MSYS2 (And a Repeater app for Windows!)

One thing many don’t consider when setting up a GTK+ window application is that the same code that runs on a Linux phone or Linux computer, can also run on MS Windows with the same libraries! Next time you are on a Windows system and trying to set up a command or tool normally working on Linux, try this:

1: Install MSYS on Windows ( from msys2.org) which has various common libraries compiled for Windows. For example, to run a Python+gtkproject with OsmGPSMap (which will include GTK and other libraries):

pacman -Syu
pacman -Su
pacman -S --needed python3
pacman -S --needed base-devel mingw-w64-x86_64-osm-gps-map
pacman -S mingw-w64-x86_64-gobject-instrospection
pacman -S mingw-w64-x86_64-python-gobject

and select Y for yes to prompts. This should install all the GTK requirements for Python and GTK, if you are working on a GTK+ application to run on Windows.

Now, when you clone or create whatever repo you are working on, you will likely want to use C:/msys64/home/yourname/ or whatever directory you have chosen when installing msys64! Then you easily have access to it in the default Msys64 terminal.

Within the Msys64 environment, you may note that running “python” console, you don’t have access to the libraries you should. In fact “import gi” does not even work. To get the full working Python3 with GTK+ libraries you must run:

/mingw64/bin/python.exe  (name of file)

Now you can test running your code, and change any adjustments to run on Windows – note there are some important differences, “/tmp” and other will never work as temp directories, but there is tempfile module to get a crossplatform temp directory.

Packaging it up

There is a library to make python files in to an exe, called Pyinstall. To install first have setuptools installed:

pacman -S mingw-w64-clang-x86_64-python-setuptools
pacman -S python3-pip
pacman -S mingw-w64-clang-x86_64-python-pywin32
pacman -S mingw-w64-x86_64-python-pywin32
pacman -S mingw-w64-x86_64-python-wheel

With pyinstaller downloaded, load it now that you have the above python-setuptools and python win32 api installed, using:

tar -xvf pyinstaller-4.9.tar.gz
cd pyinstaller-4.9
/mingw64/bin/python.exe setup.py install

and note that the pyinstaller is “/mingw64/bin/pyinstaller”, not “pyinstaller”. Installing it in a normal Python would not be helpful in building a program that use GTK+ and mingw64 libraries!

In my case I’m packaging LibOsmGpsMap which had some issues but the experts at Pyinstaller gave some helpfu guidance in bringing in the glib-networking and other libraries properly.

After it is built, an .exe runnable should be within the dist/ folder.

Packaging an Installer File

It’s fine to have the program in a folder to click and run, but folks may be tempted to move it, where it will not work without the files, or not find where it was placed when they are looking for it in the Start menu. To add it to the start menu, and the uninstall Windows apps area, you can use NSIS install creator. Make sure the files install and uninstall everything you want into the Program files directory, by testing out installing and uninstalling it a couple times.

There are a number of example “.nsi” scripts, such as this which now builds the repeater listing app. And now there is an easy double click .exe installer for the ham radio repeater app ported to Windows 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

× five = five