Forums

Can't save webp images with PIL

I have a simple function that saves a JPG as a WEBP. It works absolutely fine on my PC but when I try to run the same code on PA I got the following error:

File "/usr/local/lib/python3.4/dist-packages/PIL/Image.py", line 1654, in save
    save_handler = SAVE[format.upper()]  # unknown format
KeyError: 'WEBP'

I tried to fix it with pip installing the webp library, because I read on Stackoverflow that its needed, but unfortunately I couldn't manage that and got the below error in the Bash console:

Honestly, I have no idea what is going on in this log. I would really appreciate if you could help how could I setup WEBP support for PIL. Or if you could add WEBP to the standard library list would be amazing as well. Thanks a lot!

20:45 ~ $ pip3.4 install --user webp
Collecting webp
  Using cached https://files.pythonhosted.org/packages/62/df/1efb36189ee596f6d3773c8c1b051ada90d244a601b0e4de00181e8fa6f9/webp-0.1.0.tar.gz
    Complete output from command python setup.py egg_info:
    zip_safe flag not set; analyzing archive contents...
    conans.cli.__pycache__.cli.cpython-34: module references __file__
    conans.client.__pycache__.hook_manager.cpython-34: module references __file__
    conans.client.__pycache__.hook_manager.cpython-34: module references __path__
    conans.client.__pycache__.loader.cpython-34: module references __file__
    conans.client.__pycache__.loader.cpython-34: module references __path__

    Installed /tmp/pip-build-rjh_drhj/webp/.eggs/conan-1.34.1-py3.4.egg
    Searching for zipp>=0.4
    Reading https://pypi.org/simple/zipp/
    Downloading https://files.pythonhosted.org/packages/0f/8c/715c54e9e34c0c4820f616a913a7de3337d0cd79074dd1bed4dd840f16ae/zipp-3.4.1-py3-none-any.whl#sha256=51cb66cc54621609dd593d1787f286ee42a5c0adbb4b29abea5a63edc3e030
98
    Best match: zipp 3.4.1
    Processing zipp-3.4.1-py3-none-any.whl
    Installing zipp-3.4.1-py3-none-any.whl to /tmp/pip-build-rjh_drhj/webp/.eggs
    writing requirements to /tmp/pip-build-rjh_drhj/webp/.eggs/zipp-3.4.1-py3.4.egg/EGG-INFO/requires.txt

    Installed /tmp/pip-build-rjh_drhj/webp/.eggs/zipp-3.4.1-py3.4.egg
    Searching for pluginbase>=0.5
    Reading https://pypi.org/simple/pluginbase/
    Downloading https://files.pythonhosted.org/packages/3d/3c/fe974b4f835f83cc46966e04051f8708b7535bac28fbc0dcca1ee0c237b8/pluginbase-1.0.0.tar.gz#sha256=497894df38d0db71e1a4fbbfaceb10c3ef49a3f95a0582e11b75f8adaa030005
    Best match: pluginbase 1.0.0
    Processing pluginbase-1.0.0.tar.gz
    Writing /tmp/easy_install-2fxsmm8s/pluginbase-1.0.0/setup.cfg
    Running pluginbase-1.0.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-2fxsmm8s/pluginbase-1.0.0/egg-dist-tmp-v2r_e23w
    Downloading https://files.pythonhosted.org/packages/7e/c2/1eece8c95ddbc9b1aeb64f5783a9e07a286de42191b7204d67b7496ddf35/Jinja2-2.11.3-py2.py3-none-any.whl#sha256=03e47ad063331dd6a3f04a43eddca8a966a26ba0c5b7207a9a9e4e0
    warning: no previously-included files matching '*.pyc' found under directory 'docs'
    warning: no previously-included files matching '*.pyo' found under directory 'docs'
    warning: no previously-included files matching '*.pyc' found under directory 'tests'
    warning: no previously-included files matching '*.pyo' found under directory 'tests'
    no previously-included directories found matching 'docs/_build'
    creating /tmp/pip-build-rjh_drhj/webp/.eggs/pluginbase-1.0.0-py3.4.egg
    Extracting pluginbase-1.0.0-py3.4.egg to /tmp/pip-build-rjh_drhj/webp/.eggs

    Installed /tmp/pip-build-rjh_drhj/webp/.eggs/pluginbase-1.0.0-py3.4.egg
    Searching for bottle<0.13,>=0.12.8
    Reading https://pypi.org/simple/bottle/
    Downloading https://files.pythonhosted.org/packages/bf/44/aeafdd6ca05a8e1c3f91eeeb272a202d5cb1b3b23730a5ca686a81c48d24/bottle-0.12.19-py3-none-any.whl#sha256=f6b8a34fe9aa406f9813c02990db72ca69ce6a158b5b156d2c41f345016a723d
    Best match: bottle 0.12.19
    Processing bottle-0.12.19-py3-none-any.whl
    Installing bottle-0.12.19-py3-none-any.whl to /tmp/pip-build-rjh_drhj/webp/.eggs

    Installed /tmp/pip-build-rjh_drhj/webp/.eggs/bottle-0.12.19-py3.4.egg
    Searching for Jinja2<3,>=2.9
    Reading https://pypi.org/simple/Jinja2/
    Downloading https://files.pythonhosted.org/packages/7e/c2/1eece8c95ddbc9b1aeb64f5783a9e07a286de42191b7204d67b7496ddf35/Jinja2-2.11.3-py2.py3-none-any.whl#sha256=03e47ad063331dd6a3f04a43eddca8a966a26ba0c5b7207a9a9e4e08f1b29419
    Best match: Jinja2 2.11.3
    Processing Jinja2-2.11.3-py2.py3-none-any.whl
    Installing Jinja2-2.11.3-py2.py3-none-any.whl to /tmp/pip-build-rjh_drhj/webp/.eggs
    writing requirements to /tmp/pip-build-rjh_drhj/webp/.eggs/Jinja2-2.11.3-py3.4.egg/EGG-INFO/requires.txt

    Installed /tmp/pip-build-rjh_drhj/webp/.eggs/Jinja2-2.11.3-py3.4.egg
    Searching for tqdm<5,>=4.28.1
    Reading https://pypi.org/simple/tqdm/
    Downloading https://files.pythonhosted.org/packages/f8/3e/2730d0effc282960dbff3cf91599ad0d8f3faedc8e75720fdf224b31ab24/tqdm-4.59.0-py2.py3-none-any.whl#sha256=9fdf349068d047d4cfbe24862c425883af1db29bcddf4b0eeb2524f6fbdb23c7
    Best match: tqdm 4.59.0
    Processing tqdm-4.59.0-py2.py3-none-any.whl
    Installing tqdm-4.59.0-py2.py3-none-any.whl to /tmp/pip-build-rjh_drhj/webp/.eggs
    writing requirements to /tmp/pip-build-rjh_drhj/webp/.eggs/tqdm-4.59.0-py3.4.egg/EGG-INFO/requires.txt

    Installed /tmp/pip-build-rjh_drhj/webp/.eggs/tqdm-4.59.0-py3.4.egg
    Searching for deprecation<2.1,>=2.0
    Reading https://pypi.org/simple/deprecation/
    Downloading https://files.pythonhosted.org/packages/b9/2a/d5084a8781398cea745c01237b95d9762c382697c63760a95cc6a814ad3a/deprecation-2.0.7-py2.py3-none-any.whl#sha256=dc9b4f252b7aca8165ce2764a71da92a653b5ffbf7a389461d7a640f6536ecb2
    Best match: deprecation 2.0.7
    Processing deprecation-2.0.7-py2.py3-none-any.whl
    Installing deprecation-2.0.7-py2.py3-none-any.whl to /tmp/pip-build-rjh_drhj/webp/.eggs
    writing requirements to /tmp/pip-build-rjh_drhj/webp/.eggs/deprecation-2.0.7-py3.4.egg/EGG-INFO/requires.txt

    Installed /tmp/pip-build-rjh_drhj/webp/.eggs/deprecation-2.0.7-py3.4.egg
    Searching for future<0.19.0,>=0.16.0
    Reading https://pypi.org/simple/future/
    Downloading https://files.pythonhosted.org/packages/45/0b/38b06fd9b92dc2b68d58b75f900e97884c45bedd2ff83203d933cf5851c9/future-0.18.2.tar.gz#sha256=b1bead90b70cf6ec3f0710ae53a525360fa360d306a86583adc6bf83a4db537d
    Best match: future 0.18.2
    Processing future-0.18.2.tar.gz
    Writing /tmp/easy_install-zlb4oh96/future-0.18.2/setup.cfg
    Running future-0.18.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-zlb4oh96/future-0.18.2/egg-dist-tmp-cx4yyz0_
    warning: no files found matching '*.au' under directory 'tests'
    warning: no files found matching '*.gif' under directory 'tests'
    warning: no files found matching '*.txt' under directory 'tests'
    zip_safe flag not set; analyzing archive contents...
    future.backports.test.__pycache__.ssl_servers.cpython-34: module references __file__
    future.backports.test.__pycache__.support.cpython-34: module references __file__
    future.standard_library.__pycache__.__init__.cpython-34: module references __file__
    future.standard_library.__pycache__.__init__.cpython-34: module references __path__
    future.utils.__pycache__.__init__.cpython-34: module MAY be using inspect.stack
    past.builtins.__pycache__.misc.cpython-34: module MAY be using inspect.stack
    past.translation.__pycache__.__init__.cpython-34: module references __file__
    past.translation.__pycache__.__init__.cpython-34: module references __path__
    creating /tmp/pip-build-rjh_drhj/webp/.eggs/future-0.18.2-py3.4.egg
    Extracting future-0.18.2-py3.4.egg to /tmp/pip-build-rjh_drhj/webp/.eggs

    Installed /tmp/pip-build-rjh_drhj/webp/.eggs/future-0.18.2-py3.4.egg
    Searching for distro<=1.5.0,>=1.0.2
    Reading https://pypi.org/simple/distro/
    Downloading https://files.pythonhosted.org/packages/25/b7/b3c4270a11414cb22c6352ebc7a83aaa3712043be29daa05018fd5a5c956/distro-1.5.0-py2.py3-none-any.whl#sha256=df74eed763e18d10d0da624258524ae80486432cd17392d9c3d96f5e83cd2799
    Best match: distro 1.5.0
    Processing distro-1.5.0-py2.py3-none-any.whl
    Installing distro-1.5.0-py2.py3-none-any.whl to /tmp/pip-build-rjh_drhj/webp/.eggs

    Installed /tmp/pip-build-rjh_drhj/webp/.eggs/distro-1.5.0-py3.4.egg
    Searching for node-semver==0.6.1
    Reading https://pypi.org/simple/node-semver/
    Downloading https://files.pythonhosted.org/packages/08/51/6cf3a2b18ca35cbe4ad3c7538a7c3dc0cb24e71629fb16e729c137d06432/node_semver-0.6.1-py3-none-any.whl#sha256=d4bf83873894591a0cbb6591910d96917fbadc9731e8e39e782d3a2fbc2b841e
    Best match: node-semver 0.6.1
    Processing node_semver-0.6.1-py3-none-any.whl
    Installing node_semver-0.6.1-py3-none-any.whl to /tmp/pip-build-rjh_drhj/webp/.eggs
    writing requirements to /tmp/pip-build-rjh_drhj/webp/.eggs/node_semver-0.6.1-py3.4.egg/EGG-INFO/requires.txt

    Installed /tmp/pip-build-rjh_drhj/webp/.eggs/node_semver-0.6.1-py3.4.egg
    Searching for fasteners>=0.14.1
    Reading https://pypi.org/simple/fasteners/
    Downloading https://files.pythonhosted.org/packages/78/20/c862d765287e9e8b29f826749ebae8775bdca50b2cb2ca079346d5fbfd76/fasteners-0.16-py2.py3-none-any.whl#sha256=74b6847e0a6bb3b56c8511af8e24c40e4cf7a774dfff5b251c260ed338096a4b
    Best match: fasteners 0.16
    Processing fasteners-0.16-py2.py3-none-any.whl
    Installing fasteners-0.16-py2.py3-none-any.whl to /tmp/pip-build-rjh_drhj/webp/.eggs
    writing requirements to /tmp/pip-build-rjh_drhj/webp/.eggs/fasteners-0.16-py3.4.egg/EGG-INFO/requires.txt

    Installed /tmp/pip-build-rjh_drhj/webp/.eggs/fasteners-0.16-py3.4.egg
    Searching for patch-ng<1.18,>=1.17.4
    Reading https://pypi.org/simple/patch-ng/
    Downloading https://files.pythonhosted.org/packages/c1/b2/ad3cd464101435fdf642d20e0e5e782b4edaef1affdf2adfc5c75660225b/patch-ng-1.17.4.tar.gz#sha256=627abc5bd723c8b481e96849b9734b10065426224d4d22cd44137004ac0d4ace
    Best match: patch-ng 1.17.4
    Processing patch-ng-1.17.4.tar.gz
    Writing /tmp/easy_install-xt9eblwk/patch-ng-1.17.4/setup.cfg
    Running patch-ng-1.17.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-xt9eblwk/patch-ng-1.17.4/egg-dist-tmp-h3vtl3a0
    zip_safe flag not set; analyzing archive contents...
    Moving patch_ng-1.17.4-py3.4.egg to /tmp/pip-build-rjh_drhj/webp/.eggs

    Installed /tmp/pip-build-rjh_drhj/webp/.eggs/patch_ng-1.17.4-py3.4.egg
    Searching for colorama<0.5.0,>=0.3.3
    Reading https://pypi.org/simple/colorama/
    Downloading https://files.pythonhosted.org/packages/44/98/5b86278fbbf250d239ae0ecb724f8572af1c91f4a11edf4d36a206189440/colorama-0.4.4-py2.py3-none-any.whl#sha256=9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2
    Best match: colorama 0.4.4
    Processing colorama-0.4.4-py2.py3-none-any.whl
    Installing colorama-0.4.4-py2.py3-none-any.whl to /tmp/pip-build-rjh_drhj/webp/.eggs

    Installed /tmp/pip-build-rjh_drhj/webp/.eggs/colorama-0.4.4-py3.4.egg
    Searching for PyJWT<2.0.0,>=1.4.0
    Reading https://pypi.org/simple/PyJWT/
    Downloading https://files.pythonhosted.org/packages/87/8b/6a9f14b5f781697e51259d81657e6048fd31a113229cf346880bb7545565/PyJWT-1.7.1-py2.py3-none-any.whl#sha256=5c6eca3c2940464d106b99ba83b00c6add741c9becaec087fb7ccdefea71350e
    Best match: PyJWT 1.7.1
    Processing PyJWT-1.7.1-py2.py3-none-any.whl
    Installing PyJWT-1.7.1-py2.py3-none-any.whl to /tmp/pip-build-rjh_drhj/webp/.eggs
    writing requirements to /tmp/pip-build-rjh_drhj/webp/.eggs/PyJWT-1.7.1-py3.4.egg/EGG-INFO/requires.txt

    Installed /tmp/pip-build-rjh_drhj/webp/.eggs/PyJWT-1.7.1-py3.4.egg
    Searching for packaging
    Reading https://pypi.org/simple/packaging/
    Downloading https://files.pythonhosted.org/packages/3e/89/7ea760b4daa42653ece2380531c90f64788d979110a2ab51049d92f408af/packaging-20.9-py2.py3-none-any.whl#sha256=67714da7f7bc052e064859c05c595155bd1ee9f69f76557e21f051443c20947a
    Best match: packaging 20.9
    Processing packaging-20.9-py2.py3-none-any.whl
    Installing packaging-20.9-py2.py3-none-any.whl to /tmp/pip-build-rjh_drhj/webp/.eggs
    writing requirements to /tmp/pip-build-rjh_drhj/webp/.eggs/packaging-20.9-py3.4.egg/EGG-INFO/requires.txt

    Installed /tmp/pip-build-rjh_drhj/webp/.eggs/packaging-20.9-py3.4.egg
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-rjh_drhj/webp/setup.py", line 24, in <module>
        'License :: OSI Approved :: MIT License',
      File "/home/sabinvargas/.local/lib/python3.4/site-packages/setuptools/__init__.py", line 143, in setup
        return distutils.core.setup(**attrs)
      File "/usr/lib/python3.4/distutils/core.py", line 108, in setup
        _setup_distribution = dist = klass(attrs)
      File "/home/sabinvargas/.local/lib/python3.4/site-packages/setuptools/dist.py", line 442, in __init__
        k: v for k, v in attrs.items()
      File "/usr/lib/python3.4/distutils/dist.py", line 280, in __init__
        self.finalize_options()
      File "/home/sabinvargas/.local/lib/python3.4/site-packages/setuptools/dist.py", line 601, in finalize_options
        ep.load()(self, ep.name, value)
      File "/usr/local/lib/python3.4/dist-packages/cffi/setuptools_ext.py", line 161, in cffi_modules
        add_cffi_module(dist, cffi_module)
      File "/usr/local/lib/python3.4/dist-packages/cffi/setuptools_ext.py", line 48, in add_cffi_module
        execfile(build_file_name, mod_vars)
      File "/usr/local/lib/python3.4/dist-packages/cffi/setuptools_ext.py", line 24, in execfile
        exec(code, glob, glob)
      File "webp_build/builder.py", line 8, in <module>
        from importlib_resources import read_text
      File "/tmp/pip-build-rjh_drhj/webp/.eggs/importlib_resources-5.1.2-py3.4.egg/importlib_resources/__init__.py", line 8, in <module>
        from importlib_resources._py3 import (
      File "/tmp/pip-build-rjh_drhj/webp/.eggs/importlib_resources-5.1.2-py3.4.egg/importlib_resources/_py3.py", line 18, in <module>
        Resource = Union[str, os.PathLike]
    AttributeError: 'module' object has no attribute 'PathLike'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-rjh_drhj/webp/

It looks like some version mishmash. You use a very old deprecated python version (3.4) and one of the packages is incompatible but not advertising that in any specs.

Maybe consider an upgrade of your system image -- you can change it yourself from the "Account" page. There's more information on this help page: https://help.pythonanywhere.com/pages/ChangingSystemImage.

Changing to Python 3.6 fixed this! Thanks a lot!

Glad we could help :-)