成功在Windows的python3.8.8的32位虚拟环境上安装Pillow20231228

2023-12-28 17:03:54

我通过这篇博客分享我的经历,希望能帮助到面临类似挑战的开发者。

背景

在软件开发领域,依赖管理和兼容性问题是家常便饭。最近,我协助同事开发了一个Windows的EXE程序,其中用到了Pillow图像处理库。由于同事使用的是32位的Windows系统,我便尝试在自己的Windows 11系统上的Python 3.8.8 32位虚拟环境中安装Pillow。然而,我遭遇了兼容性的挑战,尽管网络上资源丰富,但多次尝试后仍未果。
出乎意料的是,通过一系列试验和穷举法,我最终找到了解决方案。现在,我将详细分享这个过程,希望能够帮助其他遇到类似困境的开发者。

安装报错

(32bit_venv) D:\gui_realase>pip install Pillow
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting Pillow
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/90/6e/bd5decf0621e47c635448bf45760c06c473ca36fe6152f06dfb6ffa0518e/Pillow-2.2.2.zip (2.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.2/2.2 MB 28.5 MB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: Pillow
  Building wheel for Pillow (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for Pillow (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [115 lines of output]
      running bdist_wheel
      File "d:\gui_realase\sirui32bit_venv\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
          main()
        File "d:\gui_realase\sirui32bit_venv\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "d:\gui_realase\sirui32bit_venv\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 251, in build_wheel
          return _build_backend().build_wheel(wheel_directory, config_settings,
        File "C:\Users\mathe\AppData\Local\Temp\pip-install-bhry0s4x\pillow_9b3b0ed3b5e348ff84aa12121afddde7\_custom_build\backend.py", line 53, in build_wheel
          return super().build_wheel(wheel_directory, config_settings, metadata_directory)
        File "C:\Users\mathe\AppData\Local\Temp\pip-build-env-c_a9ka_x\overlay\Lib\site-packages\setuptools\build_meta.py", line 404, in build_wheel
          return self._build_with_temp_dir(
        File "C:\Users\mathe\AppData\Local\Temp\pip-build-env-c_a9ka_x\overlay\Lib\site-packages\setuptools\build_meta.py", line 389, in _build_with_temp_dir
          self.run_setup()
        File "C:\Users\mathe\AppData\Local\Temp\pip-install-bhry0s4x\pillow_9b3b0ed3b5e348ff84aa12121afddde7\_custom_build\backend.py", line 47, in run_setup
          return super().run_setup(setup_script)
        File "C:\Users\mathe\AppData\Local\Temp\pip-build-env-c_a9ka_x\overlay\Lib\site-packages\setuptools\build_meta.py", line 311, in run_setup
          exec(code, locals())
        File "<string>", line 1005, in <module>
      __main__.RequiredDependencyException:

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

      Please see the install instructions at:
         https://pillow.readthedocs.io/en/latest/installation.html

解决方法

无意中的获取版本

(32bit_venv) D:\gui_realase>pip install Pillow==
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
ERROR: Could not find a version that satisfies the requirement Pillow== (from versions: 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7.0, 1.7.1, 1.7.2, 1.7.3, 1.7.4, 1.7.5, 1.7.6, 1.7.7, 1.7.8, 2.0.0, 2.1.0, 2.2.0, 2.2.1, 2.2.2, 2.3.0, 2.3.1, 2.3.2, 2.4.0, 2.5.0, 2.5.1, 2.5.2, 2.5.3, 2.6.0, 2.6.1, 2.6.2, 2.7.0, 2.8.0, 2.8.1, 2.8.2, 2.9.0, 3.0.0, 3.1.0rc1, 3.1.0, 3.1.1, 3.1.2, 3.2.0, 3.3.0, 3.3.1, 3.3.2, 3.3.3, 3.4.0, 3.4.1, 3.4.2, 4.0.0, 4.1.0, 4.1.1, 4.2.0, 4.2.1, 4.3.0, 5.0.0, 5.1.0, 5.2.0, 5.3.0, 5.4.0, 5.4.1, 6.0.0, 6.1.0, 6.2.0, 6.2.1, 6.2.2, 7.0.0, 7.1.0, 7.1.1, 7.1.2, 7.2.0, 8.0.0, 8.0.1, 8.1.0, 8.1.1, 8.1.2, 8.2.0, 8.3.0, 8.3.1, 8.3.2, 8.4.0, 9.0.0, 9.0.1, 9.1.0, 9.1.1, 9.2.0, 9.3.0, 9.4.0, 9.5.0, 10.0.0, 10.0.1, 10.1.0)
ERROR: No matching distribution found for Pillow==


穷举法后无意的成功

(32bit_venv) D:\gui_realase>pip install Pillow==7.0.0
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting Pillow==7.0.0
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a0/f5/943da9f188d1abdbd83f73dfba7ed8c1935161e8f9b4ef6fc9cea0b3e14b/Pillow-7.0.0-cp38-cp38-win32.whl (1.8 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 19.0 MB/s eta 0:00:00
Installing collected packages: Pillow
Successfully installed Pillow-7.0.0

没有放弃,我决定尝试安装Pillow的旧版本。经过一番尝试,我发现 Pillow==7.0.0 版本成功安装在我的32位Python 3.8环境中。这一发现是通过试错和对不同版本的穷举搜索得来的。
Pillow是一个强大的图像处理库,但在特定的系统配置和Python版本上安装它可能会遇到障碍。

结论

持之以恒:面对技术挑战时,不要轻易放弃。有时,解决方案就在下一个尝试中。
版本回退:如果最新版本不工作,尝试旧版本可能是一个好方法。

呼吁

如果你遇到了类似的问题或有其他的解决方案,欢迎在评论区分享你的经验。

文章来源:https://blog.csdn.net/Narutolxy/article/details/135270483
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。