scanny / python-pptx

Create Open XML PowerPoint documents in Python
MIT License
2.48k stars 534 forks source link

python pptx in Docker container error #796

Open FPRM opened 2 years ago

FPRM commented 2 years ago

config: OS:

Python:

I'm trying to embed a python pptx process into a docker container for AWS lambda execution as API to fill blank templates. When executing the process on my local computer (windows 10 ) everything works fine.

But when building and executing it into a Docker container it raise following error.

the docker console prints out following error

18 Mar 2022 09:26:52,340 [INFO] (rapid) exec '/usr/local/bin/python' (cwd=/function, handler=app.handler)
18 Mar 2022 09:27:14,485 [INFO] (rapid) extensionsDisabledByLayer(/opt/disable-extensions-jwigqn8j) -> stat /opt/disable-extensions-jwigqn8j: no such file or directory
18 Mar 2022 09:27:14,488 [WARNING] (rapid) Cannot list external agents error=open /opt/extensions: no such file or directory
START RequestId: ecb716fa-71a9-4db1-a2b5-3c780fe06f41 Version: $LATEST
    raise OSError("unsupported operating system")n _font_directoriesze
END RequestId: ecb716fa-71a9-4db1-a2b5-3c780fe06f41

And the API request error output following.

{
  "errorMessage": "unsupported operating system",
  "errorType": "OSError",
  "requestId": "ecb716fa-71a9-4db1-a2b5-3c780fe06f41",
  "stackTrace": [
    "  File \"/function/app.py\", line 14, in handler\n    output = fiche_pde()\n",
    "  File \"/function/function.py\", line 55, in fiche_pde\n    tf.fit_text()\n",
    "  File \"/function/pptx/text/text.py\", line 85, in fit_text\n    font_family, max_size, bold, italic, font_file\n",
    "  File \"/function/pptx/text/text.py\", line 238, in _best_fit_font_size\n    font_file = FontFiles.find(family, bold, italic)\n",
    "  File \"/function/pptx/text/fonts.py\", line 27, in find\n    cls._font_files = cls._installed_fonts()\n",
    "  File \"/function/pptx/text/fonts.py\", line 38, in _installed_fonts\n    for d in cls._font_directories():\n",
    "  File \"/function/pptx/text/fonts.py\", line 53, in _font_directories\n    raise OSError(\"unsupported operating system\")\n"
  ]
}
alterEgo123 commented 1 year ago

Did you find a solution for this?

rseeto commented 3 months ago

This is an issue with fit_text. Based on the trackback, it seems the module relies on the OS to provide information about fonts which is not provided in a Docker container. I got my Docker container to work by including a font file (.tff) and referencing the file in fit_text (e.g. fit_text(font_file='path/to/Arial.ttf')).