[R-gui] R-wxPython
James Wettenhall
wettenhall at wehi.edu.au
Mon Jun 14 09:12:59 CEST 2004
Hi,
I've been playing with an R-inteface to wxPython which has
potential to be more powerful than Tcl/Tk. Currently it works
on Windows, but so far, I haven't succeeded in getting it to
work on Linux. I haven't tried MacOS X.
http://bioinf.wehi.edu.au/folders/james/wxPython/
After I got back from useR!2004, I thought rather than
emailing out straight away to let people know that my R-wxPython
talk slides are available on the web, I would just wait until I
got R-wxPython working on Linux (as well as Windows).
"It should only take a day or two", I thought.
Now, a few weeks later, I feel like I am still making
progress, but it is very slow progress, so if there are any
Linux-minded people out there who feel like collaborating, I
would be very happy to work with you.
On Windows, you can just install Python, wxPython and RSPython
from binaries, but it's a different story on Linux :-(
Here's how to get as far as I've got to date on Linux for
R-wxPython:
1. Install R with the shared library enabled. (This can be
done with "configure --enable-shlib" when installing R
from source. The shared library will normally appear in
/usr/local/lib/R/bin/libR.so)
2. Install Python 2.2.x from source. (RSPython doesn't seem to
like 2.3.x, so don't install that. The reason I say to
install from source, is that you will need to create a
python shared library: libpython2.2.so, and this doesn't
seem to be distributed in the python RPM.)
3. Install RSPython 0.5-3 or later, being careful to link it
with the shared Python library, not a static library.
Check that RSPython.so depends on libpython2.2.so using
"ldd RSPython.so", and check that you have an
RSInternal.so symbolic link to RSPython.so in the
R/library/RSPython/libs/ directory. To get RSPython
to link to libpython2.2.so, you may have to override the
automatic configure script, e.g.
"mv configure DONTconfigure" and manually edit Makefile,
Makevars, src/Makevars etc.
4. Build wxPython 2.5.x from source (by first building
wxWidgets, distributed with wxPythonSrc). You need to modify
wxPython/config.py as follows:
(i) Change self.root = "" to self.root = None
(ii) Change newLFLAGS=[] to
newLFLAGS = ['libpython2.2.so']
Copy libpython2.2.so to the wxPythonSrc/wxPython directory.
Note that you probably don't need all of the
optional-extras like OpenGL support, so you can build with
"python setup.py build CORE_ONLY=1" or
"python setup.py install CORE_ONLY=1" to just install the
essentials.
5. Make sure that the new shared libraries are included in
LD_LIBRARY_PATH and have been registered with
/sbin/ldconfig. Some Linux systems allow you to do this
without root privileges, while others don't. I don't
have a root password, so I work mostly in my home area:
~/usr/ etc. but occasionally I need to ask for help from
root.
6. Run ldd on the wxPython shared libraries in
/usr/local/lib/python2.2/site-packages/wx/ or wherever,
to check that they depend on libpython2.2.so, otherwise you
will get errors like "Undefined symbol PyExc_IOError".
In R, type:
library(RSPython)
Ignore the following warning:
"the Python callback manager has been registered implicitly
using the defaults (referenceManager())!"
[We will use the wxPython 2.4.x method of importing the wx
module. In order understand the difference between
importPythonModule("wxPython.wx") and importPythonModule("wx"),
please read:
http://www.wxpython.org/migrationguide.php ]
Try importing the wxPython.wx module:
importPythonModule("wxPython.wx")
If it returns NULL with no errors, then it succeeded. If it
cannot be found, check your PYTHONPATH environment variable,
and if necessary, modify the Python search path within R
as follows:
importPythonModule("sys")
.Python("path",.module="sys") # Check the current Python path.
path <- "/usr/local/lib/python2.2/site-packages/wx"
.PythonEval(paste("path.append('",path,"')",sep=""),.module="sys")
# Repeat for other paths you want to add.
Now create a simple wxPython module, testRwxPy.py :
-----------------------------
import wxPython.wx
from wxPython.wx import *
def wxRPyApp():
app = wxApp()
return app
-----------------------------
Make sure testRwxPy.py can be found in your Python search path,
(using the technique above) and try:
.Python("wxRPyApp",.module="testRwxPy")
When running under R -d gdb, I get a segmentation fault which
appears to come from gdk_init_check(). :-(
A few clues from Googling "gdk_init_check segmentation fault"
and from running strace on R, suggested that it could make a
difference whether I am running X11 from a remote Linux machine
or actually sitting in front of the Linux machine.
I normally run Linux with XWin32 from Windows. I am also trying
to do some testing on a Linux machine which I am actually
sitting in front of directly, but haven't been able to run ldconfig
without root access. I will ask my administrator to do it when
he has a chance.
I hope this is of interest to a least some people on the list.
Regards,
James
--------------------------------------------------------------------------
James Wettenhall Tel: (+61 3) 9345 2629
Division of Genetics and Bioinformatics Fax: (+61 3) 9347 0852
The Walter & Eliza Hall Institute E-mail: wettenhall at wehi.edu.au
of Medical Research, Mobile: (+61 / 0 ) 438 527 921
1G Royal Parade,
Parkville, Vic 3050, Australia
http://www.wehi.edu.au
More information about the R-SIG-GUI
mailing list