importing xlwt

1,569 views
Skip to first unread message

Edwin

unread,
Jan 5, 2012, 6:05:39 PM1/5/12
to python-excel

I am using python 2.7.2 and xlwt 0.7.2. in a linux environment.

I installed python in a custom location $CUSTOMDir/python2.7.2

I installed xlwt with
$CUSTOMDir/python2.7.2/python setup.py install --home $CUSTOMDir/
python2.7.2/site-packages

and xlwt is installed in $CUSTOMDir/python2.7.2/site-packages


However, when I try to import xlwt I get back "no module named xlwt"

I have set my PYTHONPATH to $CUSTOMDir/python2.7.2/site-packages
and I have used
sys.path.append('$CUSTOMDir/python2.7.2/site-packages')
to ensure the path is present.

When I point to the lib directory in which the xlwt py and pyc files
reside and I import Workbook, then I can get the functions to work.
But the import only works in the main routine, not in the functions so
I have to instantiate the book in the main and pass it around.

It just seems a little messy as is. Suggestions?

thanks
Edwin


Gerard Blais

unread,
Jan 6, 2012, 4:39:08 PM1/6/12
to python...@googlegroups.com
I'm not on Unix anymore, but did you want ...\Lib\site-packages?

Edwin


--
You received this message because you are subscribed to the Google Groups "python-excel" group.
To post to this group, send an email to python...@googlegroups.com.
To unsubscribe from this group, send email to python-excel...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/python-excel?hl=en-GB.




--

John Machin

unread,
Jan 6, 2012, 5:39:52 PM1/6/12
to python...@googlegroups.com
Generic OS-agnostic advice:

To find out the paths where it says it will look for a module, and what python you are running:

import sys, pprint
pprint.pprint(sys.path)
print sys.version

To see where it is actually looking, run Python with the -vv arg (that's 2 * "v", not 1 * "w") and import xlwt

Why did you think it necessary to use the --home install option?

I don't understand the functions/main part of the story; the two imports in the following script should both work or both fail:

def foo():
    try:
        import xlwt
    except ImportError as e
        print "foo:", e

foo()
import xlwt

Edwin

unread,
Jan 10, 2012, 6:30:45 PM1/10/12
to python-excel

Many thanks for the input, and to the authors of this library. It is
really handy!

I am using Python 2.7.2.

I imported with --home to get the xlwt libraries to install in a
custom location. They wanted to write into /usr/local/lib without the
--home. I also just copied the .py files to the directory where I was
pointing with my import.

I (re)checked all directory names and printed out all the paths that
are being used for the import.
Still not importing xlwt, but only the specific .py file to which I
point, and then only with a from.... import.

I do not have any actual file named xlwt, not sure if there should be
one or not, and if there is not one, how python knows what to import.
The directory in which they .py files reside is named xlwt.

Oh well, got the script working so that is fine, just a small
imperfection.


Any suggestions for getting optimal speed when writing a spreadsheet.
Just one save at the end, several mid sized saves?

Again, thanks for the help and the code.
Ediwn

John Machin

unread,
Jan 30, 2012, 8:10:18 AM1/30/12
to python...@googlegroups.com


On Wednesday, 11 January 2012 10:30:45 UTC+11, Edwin wrote:

Any suggestions for getting optimal speed when writing a spreadsheet.
Just one save at the end, several mid sized saves?

Workbook.save() saves *everything* known about the workbook at the time. Just like "save as" in Excel. It's NOT an incremental save. Consequently all multiple saves (except the last) to the same path are an utter waste.
Reply all
Reply to author
Forward
0 new messages