Need help importing/installing reportlab module
Steve Holden
sholden at holdenweb.com
Tue Aug 31 07:52:32 EDT 2004
Active8 wrote:
> On Mon, 30 Aug 2004 23:24:08 -0400, Steve Holden wrote:
>
[...how to install ReportLab's open source code...]
>>
>>I'd be rather concerned that you can't find "reportlab" in the archive.
>>Basically all it contains is a "reportlab" package directory with the
>>code in it.
>
> That's what I see, just no .py or other files named reportlab.
>
Aha. The magic word is "package". See below.
>>>If anyone can help me straighten this out, I'd really apppreciate
>>>it.
>>>
>>>TIA
>>
>>Well if this doesn't fix it, please let me know.
>>
>
> when I unzip, I get
>
> ..\ReportLab_1_19\reportlab-1_19
>
Right, but this is because you chose to unzip INTO a directory you had
created called ReportLab_1_19. If you look at the archive with WinZip or
similar, you'll see that it essentially bundles everything into a
reportlab-1_19 directory. That directory contains only two things: you
identify them in your next bit. Not sure what the "..\" is doing in your
path up there ...
> which contains manifest.txt and the reportlab dir where the actual
> python code is. I've tried putting both subdirs under d:\ and
> changed the reportlab.pth path accordingly. I've changed the .pth
> file from DOS to unix and back because I read somewhere that the
> line termination char musst be just so - and I'm not even sure I got
> that right, but there's a newline in there. I even tried it without
> a newline.
>
Right. You are complicating things WAY beyond what they need to.
Something I am prone to do myself, so I feel a certain sympathy.
Delete everything you've done so far and unpack the archive into the
root directory on your D: drive. (or move what you have already, if you
feel confident doing that and you haven't messed about with the contents
of the package). This will create
D:\reportlab-1_19\MANIFEST.txt
D:\reportlab-1_19\reportlab\__init__.py
and a whole bunch of other stuff. What you are supposed to import is the
D:\reportlab-1_19\reportlab DIRECTORY: it's a package, as indicated by
the presence of the __init__.py file.
So, having got this far, you now need to create a .pth file that Python
will find (the easiest way to ensure that is to create it in the same
directory as your python.exe interpreter binary). It doesn't matter what
it's called, as long as its name ends in ".pth". It needs to contain
just one line, which reads
D:\reportlab-1_19
This will indicate to the interpreter that it can look in that directory
for the reportlab package, and bingo, you are done.
Note that if you install multiple packages you can add a line to the
same .pth file for each of the packages you want Python to find, but
that needn't concern you just now.
> I've tried forward and backslashes. Also tried running
> test_pdfgen_general.py from the command line and the python
> interpreter - can't type "d:\report* because python doesn't like
> colons - ..\report* - it doesn't like dots, either. But when I run
> it from the windows command line, it says that in
>
> line 12 of test_pdfgen_general.py
>
> from reportlab.test import unittest
> Import Error: no module named reportlab.test
>
If you can't import reportlab, what makes you think you'll be able to
import one of its sub-packages? :^)
> But I checked that test\ dir and unittest.py is there. If that's a
> clue, I don't know what to make of it.
>
> I recall installing another module - maybe PIL. When I tried that
> from x import y thing, I got an error, but the next instruction was
> to just type import PIL or whatever, and that didn't throw any
> errors.
>
> I'm pretty confused that it worked so well for you and isn't for me.
> The instructions can't be simpler.
>
Basically you are just being confused by the extra directory level
you've added, plus lack of knowledge about packages, which will be a bit
confusing until you've seen one in action.
I don't think it helps that packages aren't well-described in the
mainstream documentation, and I would encourage you to read the
description in the tutorial [Section 6.4 in my 2.3 documentation]. It
also doesn't really help that type(reportlab) is reported as <type
'module'>, adding to the potential for confusion, but once you have used
packages for a while it seems like a very natural way to bundle related
pieces of functionality.
Get back to the group again if you still can't import reportlab - it's
really worth the effort, honest! I use the o-s toolkit to do all my
invoicing.
regards
Steve
More information about the Python-list
mailing list