解决在统信UOS Linux下缺乏zlib和jpeg库导致的安装Pillow报错问题

文章讲述了在统信UOSLinux环境下,作者在Python3中安装Pillow遇到的问题,包括zlib和jpeg库缺失导致的错误,以及逐步解决的过程,最后成功安装Pillow并提供相关资源链接。
摘要由CSDN通过智能技术生成
☞ ░ 前往老猿Python博客 ░ https://blog.csdn.net/LaoYuanPython

一、引言

今天在统信UOS Linux的Python3环境下安装Pillow遇到了问题,导致安装不成功,通过报错信息。

在这里插入图片描述

二、第一执行pip3 install pillow安装报错

为了提高效率,指向了清华的镜像,具体执行指令如下:

root@jwp:~# pip3 install pillow -i https://pypi.tuna.tsinghua.edu.cn/simple 

执行安装报错,具体报错信息如下(其中有“…”这样的行表示为了节省篇幅省略了部分输出信息):

Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple 
Collecting pillow
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/00/d5/4903f310765e0ff2b8e91ffe55031ac6af77d982f0156061e20a4d1a8b2d/Pillow-9.5.0.tar.gz 
Building wheels for collected packages: pillow
  Running setup.py bdist_wheel for pillow ... error
  Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-jdaprjqf/pillow/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-4ptblh1v --python-tag cp37:
  running bdist_wheel
  running build
  running build_py
 ...........................................

  The headers or library files could not be found for zlib,
  a required dependency when compiling Pillow from source.
  
  ----------------------------------------
  Failed building wheel for pillow
  Running setup.py clean for pillow
Failed to build pillow
Installing collected packages: pillow
  Running setup.py install for pillow ... error
 
   ----------------------------------------  
    
    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 
    
    Traceback (most recent call last):
      File "/tmp/pip-install-jdaprjqf/pillow/setup.py", line 997, in <module>
     ......................................
      File "/tmp/pip-install-jdaprjqf/pillow/setup.py", line 809, in build_extensions
        raise RequiredDependencyException(f)
    __main__.RequiredDependencyException: zlib
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-jdaprjqf/pillow/setup.py", line 1010, in <module>
        raise RequiredDependencyException(msg)
    __main__.RequiredDependencyException:
    
    The headers or library files could not be found for zlib,
    a required dependency when compiling Pillow from source.
          

从上述报错信息看出,执行安装过程中,先用“Running setup.py bdist_wheel for pillow”试图为Pillow构建wheel执行安装失败,安装程序尝试使用“Running setup.py install for pillow ”执行安装,pip运行了setup.py clean来清理之前的构建文件,然后再次尝试安装Pillow,这次没有尝试构建wheel,而是直接运行了setup.py install,但还是安装失败,两次安装失败都报错:

“The headers or library files could not be found for zlib”

从上述输出信息来看,尝试安装Pillow库时遇到了错误。错误信息指出,在编译Pillow时需要的zlib库的头文件或库文件找不到。这通常意味着你的系统可能没有安装zlib开发包,或者Python环境无法找到它们。

二、第一次安装pillow报错解决

为了解决上面的zlib包未安装问题,需要安装zlib库,安装使用以下命令安装:

sudo apt-get update
sudo apt-get install zlib1g-dev

在终端中用root模式执行上述指令,成功安装了zlib。

三、第二次安装pillow报错

还是使用 pip3 install pillow -i https://pypi.tuna.tsinghua.edu.cn/simple 命令执行安装,安装继续报错,报错信息和上次不同,具体信息如下:

root@jwp:~# pip3 install pillow -i https://pypi.tuna.tsinghua.edu.cn/simple
 
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pillow
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/00/d5/4903f310765e0ff2b8e91ffe55031ac6af77d982f0156061e20a4d1a8b2d/Pillow-9.5.0.tar.gz (50.5MB)
    100% |████████████████████████████████| 50.5MB 18kB/s 
Building wheels for collected packages: pillow
  Running setup.py bdist_wheel for pillow ... error
  Complete output from command /home/administrator/Desktop/aiStudy/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-1cg913na/pillow/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-w99sle1g --python-tag cp37:
  usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
     or: -c --help [cmd1 cmd2 ...]
     or: -c --help-commands
     or: -c cmd --help
  
  error: invalid command 'bdist_wheel'
  
  ----------------------------------------
  Failed building wheel for pillow
  Running setup.py clean for pillow
Failed to build pillow
Installing collected packages: pillow
  Running setup.py install for pillow ... error
    Complete output from command /home/administrator/Desktop/aiStudy/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-1cg913na/pillow/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-05cjw5j6/install-record.txt --single-version-externally-managed --compile --install-headers /home/administrator/Desktop/aiStudy/include/site/python3.7/pillow:
    running install
    running build
    
    ----------------------------------------
    
    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
   
    ----------------------------------------

根据上述错误信息,安装Pillow时遇到了问题,具体报错为:“The headers or library files could not be found for jpeg”,这是因为缺少JPEG库的头文件或库文件,Pillow需要JPEG库来处理JPEG图像。

四、安装JPEG库

统信UOS下JPEG相关库的库名是libjpeg-dev,因此在root模式下执行如下指令安装JPEG库:

sudo apt-get install libjpeg-dev

成功安装了jpeg相关库。

五、第三次尝试安装Pillow

还是执行指令:pip3 install Pillow -i https://pypi.tuna.tsinghua.edu.cn/simple
执行后输出信息如下:

pip3 install pillow -i https://pypi.tuna.tsinghua.edu.cn/simple
 
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pillow
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/00/d5/4903f310765e0ff2b8e91ffe55031ac6af77d982f0156061e20a4d1a8b2d/Pillow-9.5.0.tar.gz
Building wheels for collected packages: pillow
  Running setup.py bdist_wheel for pillow ... error
  Complete output from command /home/administrator/Desktop/aiStudy/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-gzw0ckya/pillow/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-_sn5vftm --python-tag cp37:
  usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
     or: -c --help [cmd1 cmd2 ...]
     or: -c --help-commands
     or: -c cmd --help
  
  error: invalid command 'bdist_wheel'
  
  ----------------------------------------
  Failed building wheel for pillow
  Running setup.py clean for pillow
Failed to build pillow
Installing collected packages: pillow
  Running setup.py install for pillow ... done
Successfully installed pillow-9.5.0

从输出信息看出,在pip首次尝试安装Pillow库时遇到了一个错误,但在第二次尝试中成功安装了Pillow。

第一次尝试安装Pillow时,pip试图为Pillow构建wheel,这是一个优化的Python包分发格式,可以加快安装速度。然而,构建过程中出现了错误,提示invalid command ‘bdist_wheel’。这通常意味着setup.py脚本中存在问题,或者是因为某些依赖项没有正确安装。

第二次尝试:在第一次尝试失败后,pip运行了setup.py clean来清理之前的构建文件。然后,pip再次尝试安装Pillow,这次没有尝试构建轮子,而是直接运行了setup.py install。这次安装成功了,并且Pillow版本9.5.0被成功安装。

尽管在第一次尝试中遇到了问题,但最终Pillow库还是被成功安装了。

可以在Python环境中导入Pillow来确认安装是否成功:

from PIL import Image
image = Image.open(r'/home/administrator/F_DRIVER/pic/cat.jpg')  
image.show()

执行情况如下:
在这里插入图片描述
并成功显示:
在这里插入图片描述

上述代码能够正常运行并显示图片,证明Pillow库已经正确安装并可以使用了。

六、小结

本文介绍了在统信UOS Linux下由于缺乏zlib和jpeg库导致的安装Pillow报错问题的解决过程和解决办法,之所以报错是因为缺省的统信UOS Linux未安装zlib和jpeg库导致的,只需要安装上述库即可解决。

写博不易,敬请支持

如果阅读本文于您有所获,敬请点赞、评论、收藏,谢谢大家的支持!

更多关于统信操作系统及opencv的介绍的内容请参考专栏《国产信创之光》的其他文章。

关于老猿的付费专栏

  1. 付费专栏《https://blog.csdn.net/laoyuanpython/category_9607725.html 使用PyQt开发图形界面Python应用》专门介绍基于Python的PyQt图形界面开发基础教程,对应文章目录为《 https://blog.csdn.net/LaoYuanPython/article/details/107580932 使用PyQt开发图形界面Python应用专栏目录》;
  2. 付费专栏《https://blog.csdn.net/laoyuanpython/category_10232926.html moviepy音视频开发专栏 )详细介绍moviepy音视频剪辑合成处理的类相关方法及使用相关方法进行相关剪辑合成场景的处理,对应文章目录为《https://blog.csdn.net/LaoYuanPython/article/details/107574583 moviepy音视频开发专栏文章目录》;
  3. 付费专栏《https://blog.csdn.net/laoyuanpython/category_10581071.html OpenCV-Python初学者疑难问题集》为《https://blog.csdn.net/laoyuanpython/category_9979286.html OpenCV-Python图形图像处理 》的伴生专栏,是笔者对OpenCV-Python图形图像处理学习中遇到的一些问题个人感悟的整合,相关资料基本上都是老猿反复研究的成果,有助于OpenCV-Python初学者比较深入地理解OpenCV,对应文章目录为《https://blog.csdn.net/LaoYuanPython/article/details/109713407 OpenCV-Python初学者疑难问题集专栏目录
  4. 付费专栏《https://blog.csdn.net/laoyuanpython/category_10762553.html Python爬虫入门 》站在一个互联网前端开发小白的角度介绍爬虫开发应知应会内容,包括爬虫入门的基础知识,以及爬取CSDN文章信息、博主信息、给文章点赞、评论等实战内容。

前两个专栏都适合有一定Python基础但无相关知识的小白读者学习,第三个专栏请大家结合《https://blog.csdn.net/laoyuanpython/category_9979286.html OpenCV-Python图形图像处理 》的学习使用。

对于缺乏Python基础的同仁,可以通过老猿的免费专栏《https://blog.csdn.net/laoyuanpython/category_9831699.html 专栏:Python基础教程目录)从零开始学习Python。

如果有兴趣也愿意支持老猿的读者,欢迎购买付费专栏。

老猿Python,跟老猿学Python!

☞ ░ 前往老猿Python博文目录 https://blog.csdn.net/LaoYuanPython
  • 20
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

LaoYuanPython

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值