3

I installed the Python pdfminer module, which comes with pdf2txt.py. I can use pdf2txt.py as follows from the command line:

pdf2txt.py -o converted.html some-pdf.pdf

The pdf2txt.py file is located at:

  $ which pdf2txt.py
/usr/local/bin/pdf2txt.py

I can also import it from the interactive python command line, but to my surprise, I cannot import it in a program which I'm writing:

enter image description here

Does anybody know why this is, and more importantly, how I can solve it? All tips are welcome!

1

2 Answers 2

3

The reason is exactly because you start the interpreter from with the same directory as the script. Your script's name happens to be the same with the library name (pdf2txt). In python's search path for libraries, it will first search its current working directory (same directory where the script lives) and imported your pdf2txt.py, not the library version of pdf2txt.py.

Try rename your script to anything other than pdf2txt.py and it should work.

Sign up to request clarification or add additional context in comments.

Comments

1

Most likely because you started the interpreter from within the same directory as pdf2txt.py, which put it in your module search path. Is your python code file located in a different directory?

2 Comments

Excuse me, I should have mentioned that this is not the case. I started the interpreter from within the same directory as the script (which is a different directory from /usr/local/bin/pdf2txt.py).
Can we see the actual ImportError and a print sys.path in both your interpreter prompt and from your script?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.