Skip to content

pip error: "The headers or library files could not be found for jpeg" #5042

Closed

Description

@setanarut

What did you do?

pip3 install Pillow

What did you expect to happen?

installing the package properly without the hassle.

What actually happened?

 Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/private/var/folders/72/hplzps2136jc7fy5jf8k4hs00000gn/T/pip-install-o9zi3d_u/pillow/setup.py", line 914, in <module>
      raise RequiredDependencyException(msg)
  __main__.RequiredDependencyException:
  
  The headers or library files could not be found for jpeg,
  a required dependency when compiling Pillow from source.
  
  Please see the install instructions at:
     https://pillow.readthedocs.io/en/latest/installation.html
  ----------------------------------------
  ERROR: Failed building wheel for Pillow

What are your OS, Python and Pillow versions?

  • OS: macOS Big Sur 11.0.1
  • Python: Python 3.9.0 (default, Nov 14 2020, 10:50:03) [Clang 12.0.0 (clang-1200.0.32.27)] on darwin
  • Pillow: 8.0.1

I was able to install after a short search engine research

  1. brew install libjpeg
  2. pip3 install Pillow

Activity

  1. nulano commented on Nov 15, 2020

    @nulano
    Contributor

    These libraries are listed in the macOS installation from source instructions linked in the error message: https://pillow.readthedocs.io/en/stable/installation.html#building-on-macos

    However, this shouldn't be necessary, since Pillow does provide pre-built wheels for macOS: https://pypi.org/project/Pillow/#files (Pillow-8.0.1-cp39-cp39-macosx_10_10_x86_64.whl sounds like the right file)

    Are you using one of the new Apple Silicon Macs?

  2. setanarut commented on Nov 16, 2020

    @setanarut
    Author

    No, macbook pro 2016 intel i7

  3. setanarut commented on Nov 16, 2020

    @setanarut
    Author

    It's a packaging issue, I'm not sure if the PIP or Pillow is to blame. both are responsible.

  4. hugovk commented on Nov 16, 2020

    @hugovk
    Member

    What version of pip do you have? Does it help to upgrade it?

    We also recommend running python3 -m pip install ... (or whatever your python command is) instead of pip install ... to make it explicit which Python you're installing for.

    If it doesn't help, please can you post the full verbose output of python3 -m pip install Pillow -v

  5. setanarut commented on Nov 16, 2020

    @setanarut
    Author

    @hugovk- Big sur clean installation, everything is the latest version. Latest python3 installed with brew.

    1. brew install python3
    2. brew link python3
    3. pip3 install Pillow
      Using pip 20.2.4 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)
  6. hugovk commented on Nov 16, 2020

    @hugovk
    Member

    Thanks, what do you get when running this?

    python3 -m pip install Pillow -v
  7. setanarut commented on Nov 16, 2020

    @setanarut
    Author

    Thanks, what do you get when running this?

    python3 -m pip install Pillow -v
    1. brew uninstall libjpeg
    2. pip3 uninstall Pillow
    3. python3 -m pip install Pillow -v

    I got 683 KB, 1986 lines output. I don't want to paste it here.

    Last two lines;

    .....
    Successfully installed Pillow-8.0.1
    Removed build tracker: '/private/var/folders/72/hplzps2136jc7fy5jf8k4hs00000gn/T/pip-req-tracker-ga908n34'
    
  8. hugovk commented on Nov 16, 2020

    @hugovk
    Member

    If you don't want to paste it here, please could you upload it as a zip file or to https://gist.github.com/ or pastebin?

    The reason I ask is because it might help us find out why it's not installing a prebuilt binary wheel and is attempting to build from source.

    There should be stuff like this, showing in my case that it found Pillow-8.0.1-cp39-cp39-macosx_10_10_x86_64.whl as a potential match, and skipped those for Linux and other Python versions:

    ...
      Skipping link: none of the wheel's tags match: cp38-cp38-manylinux2014_aarch64: https://files.pythonhosted.org/packages/c0/77/ca05a9365fc72252522c1b6a6cc1f579cb5791e824480c6499b789f5a988/Pillow-8.0.1-cp38-cp38-manylinux2014_aarch64.whl#sha256=7c9401e68730d6c4245b8e361d3d13e1035cbc94db86b49dc7da8bec235d0015 (from https://pypi.org/simple/pillow/) (requires-python:>=3.6)
      Skipping link: none of the wheel's tags match: cp38-cp38-win32: https://files.pythonhosted.org/packages/f4/8c/45f28efc015ec0040bb6cbde9e763140818388938dd0d2f9e6304322f11f/Pillow-8.0.1-cp38-cp38-win32.whl#sha256=6c1aca8231625115104a06e4389fcd9ec88f0c9befbabd80dc206c35561be271 (from https://pypi.org/simple/pillow/) (requires-python:>=3.6)
      Skipping link: none of the wheel's tags match: cp38-cp38-win_amd64: https://files.pythonhosted.org/packages/d2/2c/9ac71068585b3d528349be6617ed963068bfcba3da21018cdb0d2b19f07c/Pillow-8.0.1-cp38-cp38-win_amd64.whl#sha256=cc9ec588c6ef3a1325fa032ec14d97b7309db493782ea8c304666fb10c3bd9a7 (from https://pypi.org/simple/pillow/) (requires-python:>=3.6)
      Found link https://files.pythonhosted.org/packages/b2/a2/5a1924e8af7e197c277127be7682a2491d7c1a144b008dd40830f6567bfb/Pillow-8.0.1-cp39-cp39-macosx_10_10_x86_64.whl#sha256=eb472586374dc66b31e36e14720747595c2b265ae962987261f044e5cce644b5 (from https://pypi.org/simple/pillow/) (requires-python:>=3.6), version: 8.0.1
      Skipping link: none of the wheel's tags match: cp39-cp39-manylinux1_i686: https://files.pythonhosted.org/packages/c5/a1/c922dedd3c075431395a1672413f891a5921988a7bab2c1088ff57a5897f/Pillow-8.0.1-cp39-cp39-manylinux1_i686.whl#sha256=0eeeae397e5a79dc088d8297a4c2c6f901f8fb30db47795113a4a605d0f1e5ce (from https://pypi.org/simple/pillow/) (requires-python:>=3.6)
    ...
    

    But wait!

    Successfully installed Pillow-8.0.1
    

    Looks like it's working now?

  9. setanarut commented on Nov 16, 2020

    @setanarut
    Author

    PIP installs package but Image module fails without libjpeg

    ....   
     from PIL import Image
      File "/usr/local/lib/python3.9/site-packages/PIL/Image.py", line 94, in <module>
        from . import _imaging as core
    ImportError: dlopen(/usr/local/lib/python3.9/site-packages/PIL/_imaging.cpython-39-darwin.so, 2): Library not loaded: /usr/local/opt/jpeg/lib/libjpeg.9.dylib
      Referenced from: /usr/local/lib/python3.9/site-packages/PIL/_imaging.cpython-39-darwin.so
      Reason: image not found
    
  10. setanarut commented on Nov 16, 2020

    @setanarut
    Author
  11. hugovk commented on Nov 16, 2020

    @hugovk
    Member

    Starting with Pillow 3.0.0, libjpeg is required by default, but may be disabled with the --disable-jpeg flag.

    https://pillow.readthedocs.io/en/stable/installation.html#building-from-source

  12. setanarut commented on Nov 16, 2020

    @setanarut
    Author

    Starting with Pillow 3.0.0, libjpeg is required by default, but may be disabled with the --disable-jpeg flag.

    https://pillow.readthedocs.io/en/stable/installation.html#building-from-source

    libjpeg is not the default in the operating system, but the default for Pillow. I hate ad hominem developers.

  13. wiredfool commented on Nov 16, 2020

    @wiredfool
    Member

    Please don’t be rude to the developers trying to help you on a platform released within the last week.

  14. 13 remaining items

  15. nulano commented on Dec 16, 2020

    @nulano
    Contributor

    python-pillow/pillow-team Maybe we just need to leave one of these "headers or library files" issues opened permanently … and then paste in links to other more relevant issues … e.g. "wheels for M1 macs" ?

    I think that was one of the inspirations for the new Discussions feature, as in most cases installation is not really an "issue" in Pillow (although it is in some cases).

  16. hugovk commented on Dec 16, 2020

    @hugovk
    Member

    #5093 is for the new M1 Macs, please can you try the suggestions at #5093 (comment)?

  17. hugovk commented on Dec 16, 2020

    @hugovk
    Member

    @python-pillow/pillow-team Maybe we just need to leave one of these "headers or library files" issues opened permanently … and then paste in links to other more relevant issues … e.g. "wheels for M1 macs" ?

    We could try that, and maybe lock and pin it, but I think people often find other issues via search. The M1 issue is currently 3rd in the issue list, so not that hard to find if browsing, not searching. I'll pin that too. And we probably will need some M1 changes for the next release.

  18. bschollnick commented on Jan 4, 2021

    @bschollnick
  19. Bobronium commented on Feb 15, 2021

    @Bobronium

    I have the same issue: Python 3.9, Big Sur, Intel.

    python3 -m pip install Pillow -v

    @hugovk, here's output.txt

    After running

    brew install libjpeg
    brew install freetype
    pip uninstall Pillow
    pip install Pillow

    it got installed, however, produced an error:

    Traceback (most recent call last):
      File "/Users/rocky/dev/py/jpoetry/jpoetry/image.py", line 11, in <module>
        font = ImageFont.truetype("hanZi.ttf", 50)
      File "/Users/rocky/.local/share/virtualenvs/name-hash//lib/python3.9/site-packages/PIL/ImageFont.py", line 852, in truetype
        return freetype(font)
      File "/Users/rocky/.local/share/virtualenvs/name-hash//lib/python3.9/site-packages/PIL/ImageFont.py", line 849, in freetype
        return FreeTypeFont(font, size, index, encoding, layout_engine)
      File "/Users/rocky/.local/share/virtualenvs/name-hash//lib/python3.9/site-packages/PIL/ImageFont.py", line 185, in __init__
        if core.HAVE_RAQM:
      File "/Users/rocky/.local/share/virtualenvs/name-hash//lib/python3.9/site-packages/PIL/ImageFont.py", line 44, in __getattr__
        raise ImportError("The _imagingft C module is not installed")
    ImportError: The _imagingft C module is not installed

    If I switch back to Python 3.8 it installs and works flawlessly. Any suggestions how to fix it on 3.9?

    Solution

    turns out I had old pip version in my venv, updating it solved the issue.

  20. hongquanvn1998 commented on Feb 18, 2021

    @hongquanvn1998

    @eashishkalra

    1. brew install libjpeg
    2. pip3 install Pillow

    nice. It's work for my Mac M1

  21. baijifeilong commented on Feb 20, 2021

    @baijifeilong

    apt install libjpeg for ubuntu

  22. p-hebert commented on Apr 7, 2021

    @p-hebert

    Brand new Macbook off the shelf:

    MacOS Big Sur 11.2.3
    MacBook Pro (16-inch, 2019)
    2.4 GHz 8-Core Intel Core i9

    python -m pip install --upgrade pip in venv solves the issue for me.

    Thanks to everyone who participated in this thread ❤️

  23. thewolfcommander commented on Jun 20, 2021

    @thewolfcommander

    @eashishkalra

    1. brew install libjpeg
    2. pip3 install Pillow

    That works for me too... MacBook air M1 2020. Give it a try. Trust me

  24. chrisdlangton commented on Nov 15, 2021

    @chrisdlangton

    on alpine I had to run apk update && apk upgrade && apk add --no-cache freetype-dev libpng-dev jpeg-dev libjpeg-turbo-dev

  25. ggilperez commented on Nov 27, 2021

    @ggilperez

    Brand new Macbook off the shelf:

    MacOS Big Sur 11.2.3 MacBook Pro (16-inch, 2019) 2.4 GHz 8-Core Intel Core i9

    python -m pip install --upgrade pip in venv solves the issue for me.

    Thanks to everyone who participated in this thread ❤️

    This works for me, MacBook Air M1 2020, thanks.

  26. dinkopehar commented on Oct 3, 2022

    @dinkopehar

    On MacOS Montery, installing jpeg-turbo solved a problem for Pillow==8.0.0.

  27. Didou09 commented on Oct 17, 2022

    @Didou09

    Fails for me during my Github Action workflow to build the wheel of my library:

    https://github.com/ToFuProject/tofu/actions/runs/3265080608/jobs/5366784038

    
          writing manifest file 'src/Pillow.egg-info/SOURCES.txt'
          running build_ext
      
      
          The headers or library files could not be found for jpeg,
          a required dependency when compiling Pillow from source.
      
          Please see the install instructions at:
             https://pillow.readthedocs.io/en/latest/installation.html
      
          Traceback (most recent call last):
            File "/tmp/pip-install-upaphstl/pillow_137a411b2c1640fc9ddca2e4fb5e49f0/setup.py", line 1024, in <module>
              zip_safe=not (debug_build() or PLATFORM_MINGW),
            File "/opt/_internal/cpython-3.6.15/lib/python3.6/site-packages/setuptools/__init__.py", line 153, in setup
              return distutils.core.setup(**attrs)
            File "/opt/_internal/cpython-3.6.15/lib/python3.6/distutils/core.py", line 148, in setup
              dist.run_commands()
            File "/opt/_internal/cpython-3.6.15/lib/python3.6/distutils/dist.py", line 955, in run_commands
              self.run_command(cmd)
            File "/opt/_internal/cpython-3.6.15/lib/python3.6/distutils/dist.py", line 974, in run_command
              cmd_obj.run()
            File "/opt/_internal/cpython-3.6.15/lib/python3.6/site-packages/setuptools/command/install.py", line 68, in run
              return orig.install.run(self)
            File "/opt/_internal/cpython-3.6.15/lib/python3.6/distutils/command/install.py", line 545, in run
              self.run_command('build')
            File "/opt/_internal/cpython-3.6.15/lib/python3.6/distutils/cmd.py", line 313, in run_command
              self.distribution.run_command(command)
            File "/opt/_internal/cpython-3.6.15/lib/python3.6/distutils/dist.py", line 974, in run_command
              cmd_obj.run()
            File "/opt/_internal/cpython-3.6.15/lib/python3.6/distutils/command/build.py", line 135, in run
              self.run_command(cmd_name)
            File "/opt/_internal/cpython-3.6.15/lib/python3.6/distutils/cmd.py", line 313, in run_command
              self.distribution.run_command(command)
            File "/opt/_internal/cpython-3.6.15/lib/python3.6/distutils/dist.py", line 974, in run_command
              cmd_obj.run()
            File "/opt/_internal/cpython-3.6.15/lib/python3.6/site-packages/setuptools/command/build_ext.py", line 79, in run
              _build_ext.run(self)
            File "/opt/_internal/cpython-3.6.15/lib/python3.6/site-packages/Cython/Distutils/old_build_ext.py", line 186, in run
              _build_ext.build_ext.run(self)
            File "/opt/_internal/cpython-3.6.15/lib/python3.6/distutils/command/build_ext.py", line 339, in run
              self.build_extensions()
            File "/tmp/pip-install-upaphstl/pillow_137a411b2c1640fc9ddca2e4fb5e49f0/setup.py", line 790, in build_extensions
              raise RequiredDependencyException(f)
          __main__.RequiredDependencyException: jpeg
      
          During handling of the above exception, another exception occurred:
      
          Traceback (most recent call last):
            File "<string>", line 1, in <module>
            File "/tmp/pip-install-upaphstl/pillow_137a411b2c1640fc9ddca2e4fb5e49f0/setup.py", line 1037, in <module>
              raise RequiredDependencyException(msg)
          __main__.RequiredDependencyException:
      
          The headers or library files could not be found for jpeg,
          a required dependency when compiling Pillow from source.
      
          Please see the install instructions at:
             https://pillow.readthedocs.io/en/latest/installation.html
      
      
          ----------------------------------------
      ERROR: Command errored out with exit status 1: /opt/_internal/cpython-3.6.15/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-upaphstl/pillow_137a411b2c1640fc9ddca2e4fb5e49f0/setup.py'"'"'; __file__='"'"'/tmp/pip-install-upaphstl/pillow_137a411b2c1640fc9ddca2e4fb5e49f0/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-vdxsr3c1/install-record.txt --single-version-externally-managed --prefix /tmp/pip-build-env-gcizpx28/overlay --compile --install-headers /tmp/pip-build-env-gcizpx28/overlay/include/python3.6m/pillow Check the logs for full command output.
    
      ----------------------------------------
    WARNING: Discarding file:///github/workspace. Command errored out with exit status 1: /opt/_internal/cpython-3.6.15/bin/python /opt/_internal/cpython-3.6.15/lib/python3.6/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-gcizpx28/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=40.8.0' wheel 'cython>0.26' numpy Polygon3 'datastock>=0.0.20' Check the logs for full command output.
    ERROR: Command errored out with exit status 1: /opt/_internal/cpython-3.6.15/bin/python /opt/_internal/cpython-3.6.15/lib/python3.6/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-gcizpx28/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=40.8.0' wheel 'cython>0.26' numpy Polygon3 'datastock>=0.0.20' Check the logs for full command output.
    + echo 'Building wheels failed.'
    + exit 1
    Building wheels failed.
    0s
    0s
    0s
    
    

    @nulano , any idea how to fix it for github Actions ? This is preventing me from releasing a new version...

  28. hugovk commented on Oct 17, 2022

    @hugovk
    Member

    @Didou09 If building from source, make sure you have the non-Python dependencies installed. See https://pillow.readthedocs.io/en/stable/installation.html#building-from-source

    If that doesn't help, please create a new issue. (And we no longer support Python 3.6, it's EOL since last year.)

  29. locked as resolved and limited conversation to collaborators on Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions