uploadcare / pillow-simd

The friendly PIL fork
https://python-pillow.github.io/pillow-perf/
Other
2.12k stars 85 forks source link

"headers or library files could not be found for zlib" #120

Open glitchyordis opened 1 year ago

glitchyordis commented 1 year ago

What did you do?

python -m pip install --upgrade pip python -m pip install Pillow-SIMD

I can always install Pillow without issue, the error on zlib only popups with Pillow-SIMD installation.

What did you expect to happen?

Successful installation of Pillow-SIMD.

What actually happened?

"The headers or library files could not be found for zlib, a required dependency when compiling Pillow from source."

What are your OS, Python and Pillow versions?

python -m pip uninstall -y pillow
python -m pip install --upgrade pip
python -m pip install Pillow-SIMD

pip uninstall -y pillow
pip install --upgrade pip
pip install Pillow-SIMD

image

hugovk commented 1 year ago

Please follow the installation instructions at https://github.com/uploadcare/pillow-simd#installation especially the bit about prerequisites.

barretts commented 2 months ago

Windows 11 miniconda3: 24.3.0 Python: 3.10.11

Unlike the @glitchyordis I've never been able to install Pillow. I had the same error "headers or library files could not be found for zlib" and no amount of reinstalling of pip did it for me. This little resolution story was how I cobbled mine together. Everyone said "python comes with zlib" or "reinstall pip" but none of it solved the error. I am using Windows 11. I have Visual Studio 2022 installed.

My solution starts with running pip install of pillow-simd with the --no-clean option so that the temp folder is left behind. python -m pip install --upgrade --no-clean Pillow-SIMD==9.0.0.post1

Which left all the temp files for me to use. Mine ended up in: $env:LOCALAPPDATA\Temp\pip-install-_rwbjooc\pillow-simd_3565d826dd79413698dc3519a76e6564

From that folder edit the winbuild\build_perpare.py file to modify the zlib JSON config. I also had to modify libjpeg. At the time of this writing the file had a folder of version zlib-1.3.1 that came out. My modificaiton for libjpeg was just a URL change to use the prefix https://sourceforge.net/projects.

    "zlib": {
        "url": "https://zlib.net/current/zlib.tar.gz",
        "filename": "zlib.tar.gz",
        "dir": "zlib-1.3.1",
        "build": [
            cmd_nmake(r"win32\Makefile.msc", "clean"),
            cmd_nmake(r"win32\Makefile.msc", "zlib.lib"),
            cmd_copy("zlib.lib", "z.lib"),
        ],
        "headers": [r"z*.h"],
        "libs": [r"*.lib"],
    },

Running build_prepare.py now creates a build subfolder with a bunch of cmd files. $env:LOCALAPPDATA\Temp\pip-install-_rwbjooc\pillow-simd_3565d826dd79413698dc3519a76e6564\winbuild\build

Here I ran build_dep_zlib.cmd and it built zlib and dropped the output into subfolders inc and lib.

I copied the files from inc to my $env:USERPROFILE\miniconda3\includes folder and the files from lib to $env:USERPROFILE\miniconda3\Lib.

Then running python -m pip install --upgrade Pillow-SIMD==9.0.0.post1 again worked. (Well for me it failed on libjpeg and I fixed it the same way)

Fair warning this is from memory / command history but probably has enough to get you moving forward. This was my system and my folders and in no way represents what you're working with. I hope this helps the next person!