Python 如何在树莓派上安装支持 JPEG 的 PIL?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20176883/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 19:45:58  来源:igfitidea点击:

how to install PIL with JPEG support on a raspberry pi?

pythonpython-imaging-librarypipraspberry-pi

提问by Marco Pashkov

I tried to install PILon my raspberry pi and read JPEG files. However, it does not work out of the box.

我试图在我的树莓派上安装PIL并读取 JPEG 文件。但是,它不是开箱即用的。

When I run the following:

当我运行以下命令时:

sudo pip install pil

I receive the following error, trying to open an Image:

我在尝试打开图像时收到以下错误:

""decoder jpeg not available""

While trying to install all needed JPEG libraries I ran into some errors e.g.:

在尝试安装所有需要的 JPEG 库时,我遇到了一些错误,例如:

sudo apt-get install libjpeg
E: Unable to locate package libjpeg

采纳答案by Marco Pashkov

You have to re-install PIL and also install the needed libraries as well as link them manually. This answer is based on this blog postfor a regular ubuntu PIL installation and this askubuntu question, where it is explained how to compile the jpeg encoding:

您必须重新安装 PIL 并安装所需的库以及手动链接它们。此答案基于此博客文章,用于常规 ubuntu PIL 安装和此askubuntu 问题,其中解释了如何编译 jpeg 编码:

### uninstall PIL
sudo pip uninstall pil

### download and compile the JPEG library
wget http://www.ijg.org/files/jpegsrc.v8c.tar.gz    
tar xvfz jpegsrc.v8c.tar.gz
cd jpeg-8c
./configure --enable-shared --prefix=$CONFIGURE_PREFIX
make
sudo make install

### link the libraries correctly - RASPBERRY PI ONLY
sudo ln -s /usr/lib/arm-linux-gnueabi/libjpeg.so /usr/lib
sudo ln -s /usr/lib/arm-linux-gnueabi/libfreetype.so /usr/lib
sudo ln -s /usr/lib/arm-linux-gnueabi/libz.so /usr/lib

### install rest of the libraries, as well as freetrype and zlib
sudo apt-get install libjpeg-dev libfreetype6 libfreetype6-dev zlib1g-dev

### re-install PIL
sudo pip install pil

hope that helps someone!

希望对某人有所帮助!