Building wxPython on Unix or Unix-like Systems
----------------------------------------------
-The basic steps for building wxPython for Unix or Unix-like systems
-are:
-
- 1. Compile and/or install glib and gtk+
- 2. Compile and/or install wxGTK
- 3. Compile and install wxPython
-
-We'll go into more detail of each of these steps below, but first a
-few bits of background information on tools.
-
-I use a tool called SWIG (http://www.swig.org) to help generate the
-C++ sources used in the wxPython extension module. However you don't
-need to have SWIG unless you want to modify the *.i files. I've made
-several modifications to SWIG specific to wxPython's needs and so the
-modified sources are included in the wx CVS at .../wxPython/wxSWIG.
-If you need to modify the *.i files for wxPython then change to this
-directory and run:
+NOTE: You should probably look at the ../ README.1st.txt file for
+directions for how to build wxPython the "new way." This files
+describes the "old way" to build on unix-like systems. The difference
+is very simple: The new way uses a private copy of wxGTK while the
+old way uses either an existing wxGTK that may be installed and used
+by other apps, or you can build a wxGTK that will be accissible by
+other apps.
+
+
+NOTE 2: I use a tool called SWIG (http://www.swig.org) to help
+generate the C++ sources used in the wxPython extension module.
+However you don't need to have SWIG unless you want to modify the *.i
+files. I've made several modifications to and older version of SWIG
+that are specific to wxPython's needs and so the modified sources are
+included in the wx CVS at .../wxPython/wxSWIG. But because of the
+size and since most people won't need it my SWIG is not included in
+the wxPythonSrc tarball. You'll need to get it from CVS or a CVS
+snapshot.
+
+If you need to modify the *.i files for wxPython then you will need to
+build wxswig. Change to the .../wxPython/wxSWIG directory and run:
configure
make
gtk-config --version
- If you have version 1.2.5 or better then you're all set. You can
- skip to step #2.
-
-B. If your system has a binary package mechanism, (RPMs, debs,
- whatever...) check and see if binaries for glib abd gtk+ are
- available. Be sure to get the runtime library package as well as
- the development package, if they are separate. Install them with
- your package tool, and skip to step #2.
+ If you have version 1.2.7 or better then you're all set. Otherwise
+ either get the pacakges for your unix distribution and install them
+ or get the sources from www.gtk.org and build and install them.
-C. If all else fails, you can get the source code for glib and gtk+ at
- http://www.gtk.org/. Fetch the latest of each in the 1.2.x
- series. Compile and install each of them like this:
-
- gzip -d [package].tar.gz | tar xvf -
- cd [package]
- ./configure
- make
- make install
-
- The last step will probably have to be done as root. Also, if your
- system needs anything done to update the dynamic loader for shared
- libraries, (such as running ldconfig on Linux) then do it after
- each library is installed.
+ The best version to get is the latest 1.2.x release as the
+ wxWindows support for GTK 2.x is still beta-level. (Most tings
+ work great though, and it looks real nice.)
A. You can find the sources and RPMs for wxGTK at
http://wxwindows.org/, just follow the download links from the
- nevigation panel. You can also check out a current snapshot of the
- sources from the CVS server. (Some information about annonymous
- CVS access is at http://wxwindows.org/cvs.htm.) The advantage of
- using CVS is that you can easily update as soon as the developers
- check in new sources or fixes. The advantage of using a released
- version is that it usually has had more thorough testing done. You
- can decide which method is best for you.
+ navigation panel.
+
+ Source code for wxGTK is now included with the wxPythonSrc tarball,
+ and is the recommended way to get released wxGTK source code if you
+ plan on building both.
+
+ You can also check out a current snapshot of the sources from the
+ CVS server. (Some information about annonymous CVS access is at
+ http://wxwindows.org/cvs.htm.) The advantage of using CVS is that
+ you can easily update as soon as the developers check in new
+ sources or fixes. The advantage of using a released version is
+ that it usually has had more thorough testing done. You can decide
+ which method is best for you.
+
B. You'll usually want to use a version of wxGTK that has the same
version number as the wxPython sources you are using. (Another
- advantage of using CVS is that you'll get both at the same time.)
+ advantage of using wxPythonSrc or CVS is that you'll get both at
+ the same time.)
+
C. If using the RPMs be sure to get both the wxGTK and wxGTK-devel
RPMs (at a minimum) and then install them as root.
rpm -Uhv wxGTK-2.2.2-0.i386.rpm wxGTK-devel-2.2.2-0.i386.rpm
+
D. If using the sources (either from the tarball or from CVS) then
configure it like this:
cd wxWindows # or whatever your top-level directory is called
mkdir build
cd build
- ../configure --with-gtk
+ ../configure --with-gtk --enable-geometry
There are gobs and gobs of options for the configure script, run
../configure --help to see them all. I'll describe some that I find
special debugging code in wxWindows by defining the __WXDEBUG__
macro. You'll get some extra asserts, failure logging, etc.
- To make a static library and not make a shared library, use the
- --disable-shared and --enable-static flags.
-
- NOTE: It has been discovered that some pre-built distributions of
- Python are built with options that can cause incompatibilities
- between wxPython and wxGTK. Typically these are things like large
- file support on the platforms that have it. This causes some basic
- types, like off_t, to be typedef'd differently causing the C++
- method signatures to be incompatible and giving link errors. The
- way to fix this is to activate these same settings in the wxGTK
- build, usually by looking at the flags and options used in
- compiling wxPython that are different from the options used on
- wxGTK compiles. For example, on SuSE doing the following before
- running wxGTK's configure seems to take care of it:
-
- export CFLAGS="-D_FILE_OFFSET_BITS=64 -DHAVE_LARGEFILE_SUPPORT"
- export CXXFLAGS=$CFLAGS
+ If you are using GTK 2.x then you'll want to add --enable-gtk2 and
+ probably also --enable-unicode.
E. Now just compile and install. You need to use GNU make, so if your
system needs anything done to update the dynamic loader for shared
libraries, (such as running ldconfig on Linux) then do it now.
+
F. You can test your build by changing to one of the directories under
build/samples or build/demos, running make and then running the
executable that is built.
A. You have the same options (and same advantages/disadvantages) for
getting the wxPython source, either a released snapshot or from
- CVS. The released version file is named wxPython-[version].tar.gz
+ CVS. The released version file is named wxPythonSrc-[version].tar.gz
and is available at http://wxpython.org/download.php. If you want
to use CVS you'll find wxPython in the wxWindows CVS tree (see
above) in the wxWindows/wxPython directory.
-B. As mentioned previouslly, wxPython is built with the standard
- Python Distutils tool. If you are using Python 2.0 or later you
- are all set, otherwise you need to download and install Distutils
- 1.0 from http://www.python.org/sigs/distutils-sig/.
+
+B. wxPython is built with the standard Python Distutils tool and
+ currently includes it's own snapshot of the latest version of
+ distutils which can also be used with previous versions of Python
On Unix systems Distutils figures out what commands and flags to
use for the compiler and linker by looking in the Makefile that was
used to build Python itself. Most of the time this works okay. If
it doesn't, there doesn't seem to be a way to override the values
that Distutils uses without hacking either Distutils itself, or
- Python's Makefile. (Complain to the distutils-sig about this
- please.) For example, on a Solaris system I had to edit
- /usr/local/lib/python1.5/config/Makefile and replace
-
- LDSHARED=ld -G
-
- with
-
- LDSHARED=gcc -G
-
- This particular problem has been fixed in Python 1.6 and beyond,
- but there may be similar issues on other platforms.
+ Python's Makefile. (NOTE: This has been changed with the
+ distutilsincluded with Python 2.3 but I havn't yet looked into how
+ best to utilize this in wxPython...)
While we're on the subject of how Python was built... Since
wxPython is a C++ extension some platforms and/or compilers will
make LINKCC=g++ # or whatever your C++ command is
make install
+ I recently built Python 2.1.3 and Python 2.2.1 on Solaris and did
+ not have to resort to this workaround so apparently things are
+ getting better there. I will leave this note here though in case
+ there are similar issues elsewhere. However I did run into a
+ Python build issue that affects the wxPython build when attempting
+ to use SunCC instead of GNU gcc. See the note below titled
+ "Building with non-GNU compilers" if you are interested.
+
C. Change to the root wxPython directory and look at the setup.py
file. This is the script that configures and defines all the
will be executed to regenerate the wrapper C++
and shadow python files.
- IN_CVS_TREE If you are using the CVS version of the
- wxWindows and wxPython sources then you will
- need to set this flag to non-zero. This is
- needed because some source files from the
- wxWindows tree are copied to be under the
- wxPython tree in order to keep Distutils happy.
- With this flag set then setup.py will
- automatically keep these copied sources up to
- date if the original version is ever updated.
- If you are using the tar.gz version of the
- Python sources then these copied sources are
- already present in your source tree.
+ etc.
D. To build and install wxPython you simply need to execute the
site-packages directory you may need to be root to run the install
command.
- python setup.py build
- python setup.py install
+ python setup.py build install
+
+ If you need to change any of the build flags that can also be done
+ on the setup.py command line, like this:
+
+ python setup.py BUILD_GLCANVAS=0 build install
+
+ If you are using GTK 2.x then you'll want to add these flags:
+
+ python setup.py WXPORT=gtk2 UNICODE=1 build install
+
+ If you would like to install to someplace besides the Python
+ site-packages directory (such as to your home directory) then you
+ can add "--root=<path>" after the "install" command. To use
+ wxPython like this you'll need to ensure that the directory
+ containing wxPyrthon is contained in in the PYTHONPATH environment
+ variable.
+
E. At this point you should be able to change into the wxPython/demo
directory and run the demo:
python demo.py
-F. If you would like to make a test build that doesn't overwrite the
+
+F. If you would like to make a test build that doesn't overwrite any
installed version of wxPython you can do so with this command
instead of the install command above:
python demo.py
-That's all folks!
+
+4. Building with non-GNU compilers
+----------------------------------
+
+As mentioned above Python's distutils uses whatever compiler Python
+was compiled with to compile extension modules. It also appears that
+distutils assumes that this compiler can compile C or C++ sources as
+distutils makes no differentiation between the two. For builds using
+GNU gcc and a few other compilers this is not an issue as they will
+determine the type of source from the file extension. For SunCC (and
+probably other compilers that came from cfront) it won't work as the C
+compiler (cc) is totally separate from the C++ compiler (CC). This
+causes distutils to attempt to compile the wxPython sources with the C
+compiler, which won't work.
+
+There may be better ways to get around this, but here is the
+workaround I devised. I created a script that will execute either cc
+or CC based on the file extension given to it. If Python uses this
+script for its compiler then it will also be used by extensions built
+with distutils and everybody will be more or less happy. Here is a
+copy of the script I used. It was a fairly quick rush job so there
+are probably issues with it but it worked for me.
+
+ #!/bin/bash
+ #--------------------------------------------------------------
+ # Try to determine type of file being compiled and then
+ # launch cc for C sources or CC for C++.
+ #
+
+ args=$@
+ is_C=
+
+ for arg in $args; do
+
+ # is the arg a file that exists?
+ if [ -e $arg ]; then
+
+ # does it end in ".c"?
+ if [ "${arg:${#arg}-2}" == ".c" ]; then
+ is_C=yes
+ fi
+ fi
+ done
+
+ # if the flag wasn't set then assume C++ and execute CC,
+ # otherwise execute cc.
+ if [ -z $is_C ]; then
+ exec CC -w $@
+ else
+ exec cc -w $@
+ fi
+ #--------------------------------------------------------------
+
+I called it pycc, put it in ${prefix}/bin and set its execute
+permission bit.
+
+The next step is to configure and build Python such that it uses pycc
+as it's compiler. You can do that by setting CC in your environment
+before running configure, like this in bash:
+
+ export CC=pycc
+ configure
+
+After making and installing Python with this configuration you should
+be able to build wxPython as described in the steps above.
+
-----------------