Troubleshooting
No module named 'pdfplumber': how to fix it
Almost every import failure has one of six causes, and four of them come down to installing pdfplumber into one Python and running your code with another. Run the diagnostic script below to find out which one you have.
Short answer
Install pdfplumber into the exact interpreter that runs your code, by running pip through that interpreter:
python -m pip install pdfplumber # macOS / Linux: python3 -m pip …
py -m pip install pdfplumber # WindowsIn Jupyter or Colab, run %pip install pdfplumber in a cell and restart the kernel. If the error says has no attribute ‘open’, you have a file named pdfplumber.py: rename it.
Find the cause in 10 seconds
Save this as check_pdfplumber.py and run it the same way you run the failing code: same terminal, same notebook kernel or same IDE run button. It tells you which interpreter is running, whether pdfplumber is visible to it, and whether a local file is getting in the way.
"""Why can't Python import pdfplumber? Run this the same way you run your code."""
import importlib.util
import sys
from pathlib import Path
print("Interpreter:", sys.executable)
spec = importlib.util.find_spec("pdfplumber")
if spec is None:
print("pdfplumber is not installed for this interpreter.")
print(f'Fix: "{sys.executable}" -m pip install pdfplumber')
elif spec.origin and Path(spec.origin).name == "pdfplumber.py":
print("A local file is shadowing the package:", spec.origin)
print("Fix: rename that file (and delete __pycache__ next to it).")
else:
import pdfplumber
print("Found pdfplumber", pdfplumber.__version__)
print("Location:", Path(spec.origin).parent)Interpreter: .venv/bin/python
Found pdfplumber 0.11.10
Location: .venv/lib/python3.13/site-packages/pdfplumberIf it prints not installed for this interpreter, copy the suggested command: it calls pip through that interpreter’s full path, so the package lands in the right place.
The six causes
Did you install pdfplumber at all, in this environment?
noInstall it:python -m pip install pdfplumber. A brand-new virtual environment, conda environment or Docker image starts empty, even if pdfplumber is installed elsewhere on the machine.Is the
pipyou ran attached to the Python you run?noCommon on machines with several Pythons:pipbelongs to Python 3.12,pythonis 3.13; orpipis the system one while your venv is not activated. Always usepython -m pip, and activate the venv or conda environment first (conda activate myenv).Is the code running in Jupyter, Colab or another notebook?
yesUse%pip install pdfplumberin a cell. It installs into the kernel’s interpreter.!pipruns a shell command and may install into a different Python. Restart the kernel afterwards.Does the error only show in your editor (a squiggle, not a traceback)?
yesVS Code’sImport “pdfplumber” could not be resolved(Pylance) and PyCharm’s No module named pdfplumber inspection mean the editor’s selected interpreter lacks the package. Pick the interpreter you installed into, or install into the selected one. See editors.Is any file in your project named
pdfplumber.py?yesPython imports your file instead of the library. You gethas no attribute ‘open’. Rename it. See the shadowing problem.Did you write
import pdfplumberat the top of the file?noThat is aNameError, not an install problem. Add the import. See NameError.
What the errors look like
We triggered each of these on purpose in our test workflow (GitHub-hosted runners, November 2026), so the messages below are exact.
ModuleNotFoundError: No module named ‘pdfplumber’
The interpreter that ran the code has no pdfplumber. Identical on Windows, macOS and Linux, Python 3.10 to 3.14:
Traceback (most recent call last):
File "<string>", line 1, in <module>
import pdfplumber
ModuleNotFoundError: No module named 'pdfplumber'Fix: install into that interpreter (short answer above). If you are certain it is installed, the diagnostic script will show you which interpreter is actually running.
Your file is named pdfplumber.py
If the script you are writing is called pdfplumber.py, import pdfplumber imports the script itself. The message depends on your Python version:
File "/home/runner/shadow/pdfplumber.py", line 2, in <module>
pdfplumber.open("x.pdf")
AttributeError: partially initialized module 'pdfplumber' has no attribute 'open' (most likely due to a circular import)Python 3.11 and 3.12 print the same message with a line of carets (^^^^^^^^^^^^^^^) under the call.
File "/home/runner/shadow/pdfplumber.py", line 2, in <module>
pdfplumber.open("x.pdf")
^^^^^^^^^^^^^^^
AttributeError: module 'pdfplumber' has no attribute 'open' (consider renaming '/home/runner/shadow/pdfplumber.py' if it has the same name as a library you intended to import)Fix: rename the file (for example extract_invoices.py), then delete the __pycache__ folder beside it, which may still hold a compiled pdfplumber.cpython-*.pyc. A folder named pdfplumber/ in your project causes the same problem.
NameError: name ‘pdfplumber’ is not defined
pdfplumber is installed, but the file never imports it. Notebooks hit this when the import cell was not run after a kernel restart.
# The import line is missing, so the name does not exist yet.
with pdfplumber.open("samples/invoice.pdf") as pdf:
print(pdf.pages[0].extract_text())Traceback (most recent call last):
File "name_error.py", line 2, in <module>
with pdfplumber.open("samples/invoice.pdf") as pdf:
^^^^^^^^^^
NameError: name 'pdfplumber' is not definedFix: add import pdfplumber at the top of the file, or re-run the import cell.
Editors
VS Code. Import "pdfplumber" could not be resolved (Pylance) is an editor diagnostic: your code may still run fine from a terminal. Open the Command Palette, run Python: Select Interpreter, and choose the environment you installed into (for a project venv, .venv). If the right interpreter is not listed, install into the one shown in the status bar instead.
PyCharm. Settings → Project → Python Interpreter shows the interpreter and its packages. Add pdfplumber there with the + button, or switch to the interpreter you already installed into.
Spyder and Anaconda. Spyder runs the interpreter set in Preferences → Python interpreter. If you installed with pip into a conda environment that Spyder is not using, Spyder will not see it. Install with conda install -c conda-forge pdfplumber into Spyder’s environment, or point Spyder at yours (it needs the spyder-kernels package there).
Less common causes
| Message | Cause | Fix |
|---|---|---|
ImportError: MagickWand shared library not found |
pdfplumber older than 0.10.0 used ImageMagick (via Wand) for to_image() |
Upgrade: python -m pip install -U pdfplumber. Since 0.10.0 rendering uses pypdfium2, which needs no system library. |
cannot import name 'Sequence' from 'collections' |
A very old dependency written before Python 3.10 removed those aliases | Upgrade pdfplumber and pdfminer.six together (pip install -U pdfplumber). |
ModuleNotFoundError: No module named 'pdfminer' |
pdfminer.six was uninstalled or broken separately | python -m pip install --force-reinstall pdfplumber restores the exact pdfminer.six it needs. |
Import works in the terminal, fails under sudo |
sudo runs the system Python with a different PATH |
Do not use sudo pip. Install into a venv and run that venv’s Python. |
| Works locally, fails in Docker or CI | The image or job never installs pdfplumber | Add it to requirements.txt (pinned), and rebuild the image. |