Why doesn't import work?

S

ssecorp

I have in Lib/site-packages a module named pdfminer. when I do import
pdfminer it complains:

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?
 
S

Sean DiZazzo

I have in Lib/site-packages a module named pdfminer. when I do import
pdfminer it complains:


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
 
T

Timothy Grant

I have in Lib/site-packages a module named pdfminer. when I do import
pdfminer it complains:


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?

set your PYTHONPATH environment to include the directory where your module is.
 
A

Alan Franzoni

ssecorp was kind enough to say:
I have in Lib/site-packages a module named pdfminer. when I do import
pdfminer it complains:

If you've got a directory, that's not a module - it's a package.

In order to import a directory as a package, you must create a (possibly
empty) __init__.py file in that dir.

then you can do something like

from pdfminer import pythonfile1

or you can follow Sean's advice and export the __all__ name in order to
directly access any module you like.

--
Alan Franzoni <[email protected]>
-
Remove .xyz from my email in order to contact me.
-
GPG Key Fingerprint:
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E
 
A

alex23

I have in Lib/site-packages a module named pdfminer. when I do import
pdfminer it complains:

so I apparently can't import a directory pdfminer. In the directory
pdfminer there are 3 other directoriees and inside them python-files.

Are the 3 directories called pdflib, samples & tools?
how would I import them?

The simple answer is: you -shouldn't- be.

PDFMiner is a set of tools -to be used from the command line- rather
than a PDF-handling library. You're not meant to unpack PDFMiner into
site-packages, instead you should unpack it to a temporary location
and run make. Please read the documentation on the PDFMiner site, it's
pretty clear that it's a suite of tools.

If you're after a library for dealing programmatically with PDF files,
try pyPDF:
http://pybrary.net/pyPdf/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top