Difficulty in installing PyPDF2 and PCMUPDF

Python programmers need someone to write user-friendly tools for installing useful libraries such as PyPDF2 and PcmuPDF. A modest fee would be appropriate for using such a tool. My Python program needs to access bookmarks and their page numbers in PDF files but I cannot get past the need to access the PyPDF2 and/or PcmuPDF libraries.

Both of those can be installed (at least for me, on my PC) using simple pip install pypdf2 and pip install pymupdf commands.

You’ll need to explain what you tried, what went wrong, and what error message(s) you received in order for anyone to be able to help.

Thank you so much for responding.

At the command prompt level

Pip install pypdf2


Requirement already satisfied: pypdf2in C:\users\ray\appdata]local\programs\python\python310\lib\site-packages (2.4.1)

(Similarly for pymupdf)

In Jupyter Notebook

Import PyPDF2


Error message:


1 import PyPDF2

ModuleNotFoundError: No module named ‘PyPDF2’

Hi @BrizzoRay is Jupyter running from the same virtual environment where you are installing PyPDF2?

If the pip installation is not working, maybe you can have some luck installing directly from conda-forge.

It’s always a path problem.

The command-line pip is tied to one specific Python environment, usually the system one if there’s only one Python on the system. If you have multiple Pythons, or if you have virtual environments (which you do with Conda, and maybe do with a more standalone Jupyter), that’s a different set of paths, and your packages need to be installed for that environment. Jupyter adds some extra complexities (its own idea of kernels) - it’s beyond the scope here to go into it, it’s worth doing a search on Stack Overflow for some ideas. Do try from inside Jupyter so you have an idea of where you are:

!which python
!pip list
1 Like

My problem could be that I have been installing pypdf2 from the Windows command level instead of from the Jupyter Notebook command level. But I cannot find out how to go to the command level within Jupyter Notebook. The following advice does not have any effect in the Jupyter Notepad home screen. " If you click on the prompt or output area of a cell you will enter command mode."

Unfortunately, in my experience, Jupyter has surprisingly limited convenience facilities for easily working in multiple environments compared to other scientific IDEs like Spyder. However, assuming this is just a matter of ensuring packages install in the same environment as the Jupyter kernel you are running, this comes down to one of two options:

  • Launch Jupyter Notebook in whatever Python environment you are installing packages into by typing jupyter notebook at the same command prompt. Of course, this assumes it is installed there (or you install it).
  • Figure out what Python environment Jupyter is using by checking the output of import sys; print(sys.executable) in your Jupyter Notebook. This will give either the path to the base Python install, or to the specific virtual/conda env being used. Then, activate that environment in your command prompt (will vary depending on what it is and how you installed Jupyter), and run your install commands again.

You could also running the install commands directly inside your Jupyter notebook by prefixing them with !, e.g. !pip install pypdf2, but there is no guarantee that actually works correctly, and could cause further problems.

If you still can’t figure it out, copy/paste the full, exact output of, at minimum, where python in the command prompt you are installing the packages, and import sys; print(sys.executable) inside your Jupyter notebook, inside a code block (use </> in the toolbar, or the following Markdown syntax:


This will allow us to determine where the Python environments you’re installing into and running your notebook in, respectively, are located so we can advise you how to use the latter with the former.

1 Like

Another responder named Wayne has solved my problem. His solution was:

You want to be able to type in a notebook cell to install packages from inside a Jupyter notebook.
To install your example package from within a Jupyter notebook, you want to type the following in a normal cell still in normal editing mode:

%pip install PyPDF2

That uses the pip magic command that insures the installation occurs in the environment that is backing the kernel underlying the notebook.

Thank you for your consideration of a novice in distress.

Cool. I just found out about this as well - don’t use Jupyter much. “pip magic command” indeed :slight_smile:

Firstly I was expecting to see a black window for the command level from Jupyter Notebook just like the Windows command level window. As instructed I went to an empty cell in Jupyter Notebook and typed in the command %pip install pypdf2 and then used the RUN button.

As a retired programmer now aged almost 89 I need to learn Python and write a program because no such suitable program exists. (Actually one command level program does exist but it gives faulty results and does not group the output files.) My project involves the reading of about a thousand PDF files, splitting them by top-level bookmark and then grouping the thousands of output files by bookmark. It gives me something interesting and useful to do. At this point my program gets the user to select the input and output directories and loops through the input files gathering each file’s bookmarks and page numbers. However the bookmark coding is ugly and verbose and I am looking for a better alternative. This is fun.

Mad respect—I’d be content if I was even alive at the age of 89, much less able to learn a whole new programming language…