pythonpyodide

How to import the 'PyPDF4' library in Pyodide?


"I'm trying to import the 'PyPDF4' library in Pyodide using micropip but it's giving me an error:

ValueError: Can't find a pure Python 3 wheel for 'pypdf4'.

Would anyone know what I'm doing wrong?"

async function main() {
    let pyodide = await loadPyodide();
    await pyodide.loadPackage('micropip');

    const micropip = pyodide.pyimport("micropip");
    await micropip.install('PyPDF4');

    pyodide.runPython(`
      import PyPDF4
      print(PyPDF4.__version__)
    `);
  }

  main();

Solution

  • The pypdf4 package, though it appears to be pure-python, isn't distributing a "Pure Python" wheel (ending in -any-none.whl) on PyPi. Micropip can only install packages that are either built in Pyodide or have a pure Python wheel on PyPI.

    You have a couple of options, as explained in the Pyodide Docs - building a Python wheel for yourself, or submitting a ticket with the Pyodide maintainers to see if they'll build one for you.