python-pptx icon indicating copy to clipboard operation
python-pptx copied to clipboard

python pptx in Docker container error

Open FPRM opened this issue 3 years ago • 4 comments

config: OS:

  • NAME="Debian GNU/Linux"
  • VERSION_ID="11"
  • VERSION="11 (bullseye)"

Python:

  • 3.7.13 python-pptx :

  • python-pptx==0.6.21

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"
  ]
}

FPRM avatar Mar 18 '22 09:03 FPRM

Did you find a solution for this?

alterEgo123 avatar Dec 09 '22 08:12 alterEgo123

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')).

rseeto avatar Aug 19 '24 19:08 rseeto

@rseeto were you able to get this to work in an AWS Layer? I'm trying to find one that works but haven't been able to

Chipster217 avatar Dec 12 '24 22:12 Chipster217

@Chipster217 I have only tested this with Docker and not with AWS. Have you tried running using Docker locally with the font file?

rseeto avatar Dec 16 '24 19:12 rseeto