Contents Up Previous Next

Building wxPython

I used SWIG (http://www.swig.org) to create the source code for the extension module. This enabled me to only have to deal with a small amount of code and only have to bother with the exceptional issues. SWIG takes care of the rest and generates all the repetative code for me. You don't need SWIG to build the extension module as all the generated C++ code is included under the src directory. If you try to build wxPython and get errors because SWIG is missing, then simply touch the .cpp and .py files so make won't attempt to build them from the .i files.

I added a few minor features to SWIG to control some of the code generation. If you want to play around with this the patches are in wxPython/SWIG.patches and they should be applied to the 1.1p5 version of SWIG. These new patches are documented at this site, and they should also end up in the 1.2 version of SWIG.

wxPython is organized as a Python package. This means that the directory containing the results of the build process should be a subdirectory of a directory on the PYTHONPATH, (and preferably should be named wxPython.) You can control where the build process will dump wxPython by setting the TARGETDIR makefile variable. The default is $(WXWIN)/utils/wxPython. If you leave it here then you should add $(WXWIN)/utils to your PYTHONPATH. However, you may prefer to use something that is already on your PYTHONPATH, such as the site-packages directory on Unix systems.

Win32

These instructions assume that you have Microsoft Visual C++ 5.0 or 6.0, that you have installed the command-line tools, and that the appropriate environment variables are set for these tools. You should also have Python 1.5.1 installed, and wxWindows installed and built as specified below.

  1. Build wxWindows with wxUSE_RESOURCE_LOADING_IN_MSW set to 1 in include/wx/msw/setup.h so icons can be loaded dynamically. While there, make sure wxUSE_OWNER_DRAWN is also set to 1.
  2. Change into the $(WXWIN)/utils/wxPython/src directory.
  3. Edit makefile.vc and specify where your python installation is at. You may also want to fiddle with the TARGETDIR variable as described above.
  4. Run nmake -f makefile.vc
  5. If it builds successfully, congratulations! Move on to the next step. If not then you can try mailing the wxwin-developers list for help. Also, I will always have a pre-built win32 version of this extension module at http://alldunn.com/wxPython.
  6. Change to the $(WXWIN)/utils/wxPython/tests directory.
  7. Try executing the test programs. Note that some of these print diagnositc or test info to standard output, so they will require the console version of python. For example:

    python test1.py

    To run them without requiring a console, you can use the pythonw.exe version of Python either from the command line or from a shortcut.

Unix

These directions assume that you have already successfully built wxWindows for GTK, and installed Python 1.5.1. If you build Python yourself, you will get everything installed that you need simply by doing make install. If you get Python from an RPM or other pre-packaged source then there will probably be a separate package with the development libraries, etc. that you will need to install.

  1. Change into the $(WXWIN)/utils/wxPython/src directory.
  2. Edit Setup.in and ensure that the flags, directories, and toolkit options are correct, (hopefully this will be done by configure soon.) See the above commentary about TARGETDIR. There are a few sample Setup.in.[platform] files provided.
  3. Run this command to generate a makefile:

    make -f Makefile.pre.in boot

  4. Once you have the Makefile, run make to build and then make install to install the wxPython extension module.
  5. Change to the $(WXWIN)/utils/wxPython/tests directory.
  6. Try executing the test programs. For example:

    python test1.py