-
Notifications
You must be signed in to change notification settings - Fork 2
BuildOnWindows
How to run the program from source on windows and build it into an executable.
I will first describe the process necessary to run this program from source. I will then describe how to build the program into a self contained executable that can be run by anybody.
In order to run my program, you will need to install python, the Numeic python package, the PIL. I built my program with Python 2.5.1 and all with python2.5 builds of the packages. You can get the windows installer here. I then installed the win32all python extension (I am really not sure if you need this). You can get it here. I ended up getting the installer names pywin32-210.win32-py2.5.exe. I then got PIL from here. I downloaded and installer named "Python Imaging Library 1.1.6 for Python 2.5". I then installed a build of Numeric python for Python 2.5 that I found here. The installer was called Numeric-24.2.win32-py2.5.exe. I then ran all these installers to get all of the packages that I needed. I then installed py2exe. You can get it here. The installer that I got was called py2exe-0.6.6.win64-py2.5.exe. I then ran all these installers. I had to manually add python to my path. To do so, I followed the instructions here adding C:\python25 to the path. I finally installed Pmw. To do so, I went here to get it and downloaded the file called Pmw.1.3.2.tar.gz. I untarred it and then from the command line moved into the folder and issued the command python setup.py install. This gets us Pmw and we should have everything we need.
To build the C extensions that my program uses, I installed MinGW. I got the installer here. I then selected to download the "Automated MinGW Installer" and ran that. I then did a custom install and make sure to check it so that it would install g++ compiler and the MinGW Make. Once we have MinGW, we can use this to build the extensions. In principle, I you can use Visual Studio 2003 to build the extensions. But I don't have that and MinGW is free. So once I installed MinGW, I put "C:/MinGW/bin/" into the path just like above.
Once we have MinGW, we can build the python extensions. Go to my source folder. First, we need to install the external library package levmar. To do so, go into the wrap/levmar/ folder and issue the command
$ C:/MinGW/bin/mingw32-make.exe
This is analogous to saying make when in linux. This will build the package and at the end there will be a warning about not having the package levmar. That is fine. If you now go back to the wrap/ folder, you can issue the following command to make python build all the C extension so that they can be used by the program:
$ python setup.py build --compiler=mingw32
The --compiler flag allows you to build python extensions without using Microsoft's compiler.
By the way, I was having a little bit of trouble with extensions because running the setup script, it would put all the .pyd (something like python executable files) in the folder wrap\build\lib.win32-2.5 but would not put them in a place globally accessible by python. This probably has to do with my having Windows (or some configuration) set up improperly, but instead of worrying about how to fix this, I just moved all the .pyd files into the folder with the rest of the source code and python was happy after that.
Once you do that, you can go back to the folder with the source code in it and run the program with the command
$ python AreaDiffractionMachine
Before building the program into a standalone executable using py2exe, I had to freeze it into the current folder. You don't have to do this to build the program anymore because I already did, but I will document here what I did anyway for reference. The desired process is described at http://pmw.sourceforge.net/doc/dynamicloader.html. This process created the file Pmw.py inside of the current folder. This file can then be used to include Pmw in py2exe. This new Pmw file can now be imported as "import Pmw" and py2exe will be happy. The only problem is that python gets confused about which Pmw.py I am trying to import. To fix this problem, I renamed this file to PmwFreeze.py. I then issued the command inside of my program "import PmwFreeze as Pmw" and it uniquely includes the right frozen Pmw. This lets me have Pmw widgets inside of an py2exe executable! After I did this, on the Mac the file PmwFreeze.py was giving me this silly error:
File "/Users/jolande/xrd work/areadiffractionmachine/source/version1/PmwFreeze.py", line 1814, in _reporterror
msg = exc_type + ' Exception in Tk callback\n'
So, I changed the line to:
msg = str(exc_type) + ' Exception in Tk callback\n'
And everything worked after that.
Building the program using py2exe is easy because I wrote a script that does all the hard work. To run the script, go into the build/ folder and then issue the command:
$ python setup_win_version1.py py2exe --version=X.X.X
The version string "X.X.X" should be replaced with whatever version you are building - like "1.0.1", or whatever. The script will build the program into an executable, rename the executable to have the version name in it, rename the folder containing the executable to have the version string in it, and then zip up the file for easy distribution. Once the script is done, you can do whatever you want with the executable. Pretty easy!