Using xlrd with IronPython: HOWTO

668 views
Skip to first unread message

John Machin

unread,
Feb 3, 2008, 3:20:34 PM2/3/08
to python-excel
The released version of xlrd (0.6.1) can be used with IronPython.
These notes explain how. They apply equally to any pure-Python
package.

1. Install Python 2.4 (latest version) if you don't already have it.
2. Run the Windows installer for xlrd 0.6.1, pointing it at Python 2.4
3. Check that you can use xlrd with Python 2.4.
4. Ensure that the Python 2.4 Lib and Lib\site-packages directories
are in IronPython's sys.path:

Either (a) append the following lines to <IronPython installation
directory>\Lib\site.py:

sys.path.extend([
r'c:\Python24\Lib',
r'c:\Python24\Lib\site-packages',
])

or (b) put those lines at the top of your source file(s) before
"import xlrd" -- you may like to make this conditional ... """if
'IronPython' in sys.version:""" seems to work OK.

The above assumes that <Python 2.4 installation directory> is c:
\Python24 -- if not, adjust accordingly.

This has been tested minimally with IronPython 1.1.1 and not at all
with IronPython 2.*alpha.

The time to open a largeish workbook with IronPython 1.1.1 can be 2x
to 3x the time taken with Python 2.5.

Cheers,
John

John Machin

unread,
Feb 4, 2008, 4:48:50 AM2/4/08
to python...@googlegroups.com
Sallu wrote:

Please reply to the list / newsgroup. That way you get a much larger
audience, which might actually include somebody who knows something
about IronPython -- I know little more than what I posted in the HOWTO.

> yeah sir as u said i set the path with python 2.4 and its working with
> IronPython 1.1.1 really i am glad.
> but when i used with Microsoft IronPython for ASP.NET(which i
> installed there is only 2 folder named WebAppTemplate,LanguageService
> and one file AddPyScriptMap) and tried with default.aspx.py like this
> import System
> from System.Data import *
> from System.Web import *
> from System.Web.UI import *
> from IronPython.Hosting import PythonEngine
>
> from clr import *
> import sys
> import clr
> sys.path.extend([
> r'd:\Python24\Lib',
> r'd:\Python24\Lib\site-packages',
> ])
> import xlrd
> book = xlrd.open_workbook("myfile.xls")
>
>
Here you should insert some code to show that you have successfully
opened the workbook e.g.
print >> sys.stderr, book.sheet_names()

The following code seems totally irrelevant to the problem ....
> import SampleModule
> from SampleModule import SampleClass
> def Page_Load():
> pass
> _PrivateMethod("1")
> PublicMethod("2")
> def _PrivateMethod(text):
> lblPrivate.Text="private %s" %text
> def PublicMethod(text):
> lblPublic.Text="public %s" %text
> def Private_Click(sender,args):
> _PrivateMethod("3")
> def Button1_Click(sender, args):
> sc = SampleClass()
> sc.TestString = TextBox1.Text
> Label1.Text = sc.TestString
> Label1.Visible="True"
> Then its showing error --------------->.. Value cannot be null.
> Parameter name: encoding.
What is "it"? Do you mean that "it" showed "..Value cannot be null.
Parameter name: encoding. " and no other information??? Don't you get a
traceback???
What function/method has a parameter whose name is "encoding" and whose
value allegedly cannot be null??

> now i am happy atleast with the help of you
> i am able to resolve that error xlrd module is not found. please help
> me out to resolve this error.
>
>
Without a traceback I can't help you. Even with a traceback you may need
to ask on one of the IronPython forums what "Value cannot be null"
really means.

Cheers,
John

Kelie

unread,
Mar 26, 2008, 12:23:49 PM3/26/08
to python-excel
On Feb 3, 10:20 am, John Machin <sjmac...@lexicon.net> wrote:
> The released version of xlrd (0.6.1) can be used with IronPython.
> These notes explain how. They apply equally to any pure-Python
> package.

John,

When you say "pure-Python package", do you mean any package that comes
with a standard Python distribution?

Thanks.

Chris Withers

unread,
Mar 26, 2008, 12:33:49 PM3/26/08
to python...@googlegroups.com
Kelie wrote:
> When you say "pure-Python package", do you mean any package that comes
> with a standard Python distribution?

Not sure what you mean by this...

- xlrd is *not* included in the standard python distribution

- don't know what you mean by "package", you're not using the term in
it's normal python context ;-)

- John's comments mean that xlrd doesn't have any extension modules, so
xlrd will run happilly on normal Python, Jython or IronPython.

cheers,

Chris

--
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk

Kelie

unread,
Mar 26, 2008, 7:07:32 PM3/26/08
to python-excel
On Mar 26, 6:33 am, Chris Withers <ch...@simplistix.co.uk> wrote:
> Kelie wrote:
> > When you say "pure-Python package", do you mean any package that comes
> > with a standard Python distribution?
>
> Not sure what you mean by this...
>

Thanks Chris. When I say, I meant modules. Any module that comes with
the standard python installation such as re, time, urllib, etc.. would
be available in IronPython by appending the Lib and Lib\site-packages
directories to sys.path. Correct? I thought there are some modules
from CPython that are not implemented in IronPython yet.

John Machin

unread,
Mar 26, 2008, 7:44:28 PM3/26/08
to python...@googlegroups.com

1. "pure-Python": source code is in Python, no C.*, assembler, etc

2. "package": consists of 1 or more modules

3. appending those directories to sys.path allows access to pure-Python
packages in the *CPython* distribution (Lib) or 3rd-party packages that
have been installed in site-packages.

4. If you want to import a package that comes with CPython and includes
C code and has not been implemented in IronPython [check the IronPython
website], you are out of luck ... IronPython won't use .pyd files.

Cheers,
John

Kelie

unread,
Mar 27, 2008, 12:54:20 PM3/27/08
to python-excel
On Mar 26, 1:44 pm, John Machin <sjmac...@lexicon.net> wrote:
> 1. "pure-Python": source code is in Python, no C.*, assembler, etc
>

John, thanks for the clarification. I'm glad to find out that. It
means I will be able to use many 3rd party packages/modules in
IronPython.
Reply all
Reply to author
Forward
0 new messages