Reputation: 171
I'm using Python 3.5 with the Anaconda distribution. tabula-py version 1.1.1 is installed. When I run the following simple program:
import tabula
df = tabula.read_pdf("sample.pdf", pages=1, encoding="ISO-8859-1")
df.columns = df.iloc[0]
df.drop(0, inplace=True)
I get the following error message:
AttributeError: module 'tabula' has no attribute 'read_pdf'
HOWEVER: If I open Spyder and first type "import tabula" in the IPython console before running the code, it runs just fine. If I restart the kernal, I get the same error until I close and reopen Spyder.
Any thoughts? Thanks in advance.
Upvotes: 1
Views: 707
Reputation: 13175
Spyder has a shared namespace between your console and your scripts. I answered the reverse of this problem here.
Anything defined in the console will be accessible in the namespace of the scripts you run. The module imports are cached across all of your scripts, so you can import it once in the console and then access it in all of your scripts indefinitely (until you reset the kernel).
You should not rely on this behaviour because the script will not work outside of Spyder. Instead, you should explicitly import the module at the top of your script.
In this case, it's likely that you've called your script tabula.py
and you should rename it.
Upvotes: 2