Install Pandoc inside Azure Function for Pypandoc

563 Views Asked by At

I am using the package pypandoc for converting DOC/DOCX files into HTML. This has a prerequisite of Pandoc being already installed. When both packages are installed using the requirements.txt file, it works locally. When I deploy it as an Azure Function, however, it always gives a "module not found" error. (pypandoc cannot find pandoc in the same path because it gets installed elsewhere.)

This seems like a known issue. Pandoc does not get installed in the same path as Pyandoc and there are multiple solutions suggested. But they only locally.

Options tried:

  1. Use pandoc_download

      from pypandoc.pandoc_download import download_pandoc
    
  2. Use wdc. This does not fix the problem.

  3. Use wheel files that include Pandoc.

Right now I am using mammoth for conversion which is slightly lower in accuracy, but gets deployed on Az. How can I get Pypandoc working as an Azure Function? How can I install Pandoc in a place where Pypandoc can find it? Or, how can I tell Pypandoc where to find Pandoc?

1

There are 1 best solutions below

0
On

I test it in my side, I install pandoc and pypandoc in local by the command pip install pypandoc and pip install pandoc but not install them using requirements.txt. The function works fine in local.

And then I generate the requirements.txt by running the command pip freeze > requirements.txt. Then deploy the function to azure by running the command func azure functionapp publish <your function app name> --build remote, azure will install the modules according the content of requirements.txt. After the deployment, the function run success on azure portal.