Publishing error: TypeError with matplotlib

Dear VIKTOR team,

I am encountering the following error while publishing the app. Could you please help me to solve it?

 SUCCESS  uploading completed!
  ERROR   packing completed with errors: Could not generate manifest:
           2023-11-14 14:33:59.742 ERROR   : expected str, bytes or os.PathLike object, not PosixPath
          Traceback (most recent call last):
            File "viktor_connector/connector.pyx", line 692, in
            File "/tmp/wd/app-code-layer/home/user/src/app/", line 2, in <module>
              from .my_entity_type.controller import MyController as MyEntityType
            File "/tmp/wd/app-code-layer/home/user/src/app/my_entity_type/", line 12, in <module>
              from matplotlib import pyplot as plt
            File "/tmp/wd/site-packages-layer/usr/local/lib/python3.9/site-packages/matplotlib/", line 963, in <module>
              rcParamsDefault = _rc_params_in_file(
            File "/tmp/wd/site-packages-layer/usr/local/lib/python3.9/site-packages/matplotlib/", line 866, in _rc_params_in_file
              with _open_file_or_url(fname) as fd:
            File "/usr/local/lib/python3.9/", line 119, in __enter__
              return next(self.gen)
            File "/tmp/wd/site-packages-layer/usr/local/lib/python3.9/site-packages/matplotlib/", line 842, in _open_file_or_url
              fname = os.path.expanduser(fname)
            File "/usr/local/lib/python3.9/", line 231, in expanduser
              path = os.fspath(path)
          TypeError: expected str, bytes or os.PathLike object, not PosixPath

INFO: Encountered an error during monitoring of deployment. Use the `apps` command to see the current status of the deployment.

What version of Matplotlib do you use? When searching for this issue online I find many people having this problem and having to downgrade in version.

Hi Bart @bvanderhulst,

Thanks for your reply. I was using matplotlib version 3.8.1. I tried downgrading matplotlib to 3.0.3 as the stackoverflow post hinted, but I got stuck. I also downloaded freetype and png, but it seems that my computer can’t find the packages.

python -m pip install matplotlib==3.0.3   
Collecting matplotlib==3.0.3
  Using cached matplotlib-3.0.3.tar.gz (36.6 MB)
  Preparing metadata ( ... error
  error: subprocess-exited-with-error
  × python egg_info did not run successfully.
  │ exit code: 1
  ╰─> [47 lines of output]
      Edit setup.cfg to change the build options
                  matplotlib: yes [3.0.3]
                      python: yes [3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022,
                              16:36:42) [MSC v.1929 64 bit (AMD64)]]
                    platform: yes [win32]

                       numpy: yes [version 1.26.0]
            install_requires: yes [handled by setuptools]
                      libagg: yes [pkg-config information for 'libagg' could not
                              be found. Using local copy.]
                    freetype: no  [The C/C++ header for freetype
                              (freetype2\ft2build.h) could not be found.  You may
                              need to install the development package.]
                         png: no  [The C/C++ header for png (png.h) could not be
                              found.  You may need to install the development
                       qhull: yes [pkg-config information for 'libqhull' could not
                              be found. Using local copy.]

                 sample_data: yes [installing]
                    toolkits: yes [installing]
                       tests: no  [skipping due to configuration]
              toolkits_tests: no  [skipping due to configuration]

                         agg: yes [installing]
                       tkagg: yes [installing; run-time loading from Python Tcl /
                      macosx: no  [Mac OS-X only]
                   windowing: yes [installing]

                        dlls: no  [skipping due to configuration]

                              * The following required packages can not be built:
                              * freetype, png
                              * Please check
                              * ges/freetype.htm for instructions to install
                              * freetype
                              * Please check
                              * ges/libpng.htm for instructions to install png
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

Are there any other VIKTOR apps using matplotlib/png? Something like this? And encountering the same error? If not, which version are they using?

            png_data = BytesIO()
            fig_plt.savefig(png_data, format='png', bbox_extra_artists=(lgd, text), bbox_inches='tight')

Btw, I am using viktor-cli v0.31.2

I managed to debug this issue. I found somebody writing that - in my own words, as I have very little understanding of Windows/Linux or publishing issues - a Linux system doesn’t like the pathlib package.

So, I removed the pathlib dependency in my requirements.txt-file, and now the VIKTOR app is published!

1 Like