Archive for the ‘python’ Category

wxPython hourglass cursor not working in Ubuntu

Monday, August 17th, 2009

The following code worked in Windows but not in Ubuntu:

# hourglass cursor

curs = wx.StockCursor(wx.CURSOR_WAIT)
self.SetCursor(curs)
Something happens that takes a while … … … …
# Return to normal cursor
curs = wx.StockCursor(wx.CURSOR_ARROW)
self.SetCursor(curs)

Use instead:

wx.BeginBusyCursor()
wx.EndBusyCursor()

NB good to use wx.IsBusy() with EndBusyCursor().  On Windows, ending a cursor if one is not running causes an error.

if wx.IsBusy():
    wx.EndBusyCursor()

Misc library issues

Monday, August 17th, 2009

Re: pysqlite-2.5.5-win32-py2.6.exe – it wouldn’t install on my clean virtual XP environment.  It was unable to locate the component msvcr71.dll. So I was forced to include that in the Windows package.

The mysqldb module doesn’t currently have an official 2.6 version of the Windows installer.  Which was the main reason I had kept the Windows version to Python 2.5 for which there was one  (SciPy was no longer relevant so shifting to 2.6 for all installers was definitely in contention).  And there had been mixed experience of mysqldb packages put together by third parties (https://sourceforge.net/forum/forum.php?thread_id=2316047&forum_id=70460).  But I really needed a feature which was introduced in Python 2.6 – namely the float method as_integer_ratio.  This was needed to enable my float to decimal function to work (http://docs.python.org/library/decimal.html) which I needed to get the level of precision required to pass the hardest NIST ANOVA test (http://www.itl.nist.gov/div898/strd/anova/SmLs09.html). In the end I went with http://www.thescotties.com/mysql-python/test/MySQL-python-1.2.3c1.win32-py2.6.exe.  Another option was http://www.codegood.com/archives/4.

BTW there is a lot to like about Python 2.6 – it is the gateway to the 3 series and will make that eventual transition a lot easier.

The decimal module in Python

Wednesday, August 12th, 2009

Python has a brilliant decimal module (http://docs.python.org/library/decimal.html) you may need if you want to avoid floating point errors.  This may be necessary if you are faced with compounding errors under special circumstances e.g. if testing a statistical routine against a purpose-built test dataset (e.g. http://www.itl.nist.gov/div898/strd/anova/SmLs09_cv.html).  The performance hit is substantial, however, so it has to be used judiciously.  Anyway, here is an example:

import decimal
D = decimal.Decimal
decimal.getcontext().prec = 120
d1 = D("1.1")
f1 = 1.1
print "Decimal result is: %s" % round((d1**1000 - D("2.46993291801e+41")),3)
print "Floating point result is: %s" % round((f1**1000 - 2.46993291801e+41),3)
>>>

Decimal result is: -4.17366587591e+29
Floating point result is: -3.97456123863e+29

Usually, floating point is good enough – but not under all circumstances.  In which case, it pays to be familiar with the decimal module.

Adding ability to import from csv and spreadsheets etc

Tuesday, June 9th, 2009

SOFA Statistics is having new import functionality added.  The first target is csv format files (using the standard Python csv module underneath) followed by Excel spreadsheets.  The solution I have for Excel works even when MS Office has not been installed on a machine but will only work in Windows.   Later on I will target SPSS data files and Open Office Calc spreadsheet files.

Resolving Windows installation glitches

Tuesday, May 26th, 2009

If you had problems installing the Windows version of SOFA 0.6.8, try 0.7.0 (http://www.sofastatistics.com/misc/sofa-0.7.0_python-2.5.zip).  It resolves the main issues with that installation package.  Version 0.7.0 also resolves some other issues within SOFA and represents the first of the 0.7 series – the goal of which is to enable importing of spreadsheets and other, non-SQL database type data.

The Windows comtypes package relied upon by SOFA 0.6.8 proved to be faulty.  The 0.7.0 version of SOFA Statistics, which has just been released, uses an older version of comtypes (0.5.2) which is known to work.  A version of comtypes 0.6.0 for python 2.5 is apparently forthcoming.

There is still a delay when using SOFA’s table making functionality for the first time while comtypes generates some data it needs.  NB this is a one-off delay which doesn’t affect anything else.  Ideally, SOFA will handle this process better in a forthcoming release.

Windows package will be Python 2.5 only for now

Saturday, May 16th, 2009

Unfortunately SciPy does not have a Python 2.6 installer yet.  The MySQLdb package does but it is not from the central sourceforge location (http://www.technicalbard.com/files/MySQL-python-1.2.2.win32-py2.6.exe). Also see http://bytes.com/groups/python/854793-will-mysqldb-python-shim-supported-python-2-6-3-x.  For the time being, therefore, the Windows package for SOFA will be a Python 2.5 version only.

BTW nearly ready to release the packages once project hosting is finalised.

The licence is AGPL 3.

SOFA for Windows Package under testing

Friday, May 15th, 2009

A windows installer for sofa statistics has been created and is currently undergoing testing on clean machines.  NSIS was used to create the installer, which necessitated learning a new script language.  The language used by NSIS is a cross between PHP and assembly and was quite a shock after the elegance of python.

Made first demo deb package successfully

Friday, May 8th, 2009

The instructions kindly provided by Horst Jens  at http://showmedo.com/videotutorials/video?name=linuxJensMakingDeb were very helpful.  There are a few details I have to understand better but it all looks doable.  One gotcha when editing the rules file in gedit – tabs != spaces and manually added tabs are converted into spaces!  Copying and pasting tabs from elsewhere solved the problem.