Why doesn't import work?

Benjamin Kaplan benjamin.kaplan at case.edu
Mon Aug 4 19:25:04 EDT 2008


On Mon, Aug 4, 2008 at 6:40 PM, Sean DiZazzo <half.italian at gmail.com> wrote:

> On Aug 4, 3:34 pm, ssecorp <circularf... at gmail.com> wrote:
> > I have in Lib/site-packages a module named pdfminer. when I do import
> > pdfminer it complains:
> >
> > >>> import pdfminer
> >
> > Traceback (most recent call last):
> >   File "<pyshell#3>", line 1, in <module>
> >     import pdfminer
> > ImportError: No module named pdfminer
> >
> > I created a file pdfminer.py and put it in site-packages and that
> > works.
> >
> > so I apparently can't import a directory pdfminer. In the directory
> > pdfminer there are 3 other directoriees and inside them python-files.
> >
> > how would I import them?
>
> Make packages?
>
> I just (finally) got around to learning this the other day...
>
> make a file called __init__.py in each of you lib subfolders
> in each do something like:
>
> all = ["file1.py", "file2.py", "file3.py"]
>

> Then you should be able to import each directory as a package, and
> access the individual modules.
>
> ~Sean


Just having an __init__.py file makes the directory a python package, even
if __init__.py is blank.

http://docs.python.org/tut/node8.html#SECTION008400000000000000000
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080804/7195e75e/attachment-0001.html>


More information about the Python-list mailing list