在Ubuntu 12.04 Python 2.7和Python 3.2中安装PIL。

时间:2023-01-04 00:24:58

I am, using Ubuntu 12.04 server which by default has two versions of Python: 2.7 and 3.2. When I install PIL using the python setup.py install terminal command, the PIL will be installed with Python 2.7. How to install PIL with Python 3.2? Because I'm using Python 3 to write my script. If my Eclipse uses Python 2.7, PIL is successfully imported. But if I choose Python 3 as my Grammar language, PIL fails to import.

我使用Ubuntu 12.04服务器,默认有两个版本的Python: 2.7和3.2。当我使用python设置安装PIL。py安装终端命令,PIL将安装Python 2.7。如何使用Python 3.2安装PIL ?因为我在用python3来写我的脚本。如果我的Eclipse使用了Python 2.7, PIL就成功导入了。但是如果我选择Python 3作为我的语法语言,PIL就不能导入了。

P/S: I have tried the following:

P/S:我试过以下方法:

  • Pillow PIL (Pillow-1.7.8.zip )
  • 枕头公益诉讼(Pillow-1.7.8。邮政编码)
  • Aspell PIL (PIL-1.1.7-py3-source.zip)
  • Aspell公益诉讼(PIL-1.1.7-py3-source.zip)

UPDATE:

更新:

Using the python3 command results in an error message.

使用python3命令会导致错误消息。

Example 1:

示例1:

root@sys:~/Downloads/Pillow-1.7.8# python3.2 setup.py install
Traceback (most recent call last):
  File "setup.py", line 10, in <module>
    from setuptools import Extension, setup, find_packages
ImportError: No module named setuptools

Example 2:

示例2:

root@sys:~/Downloads/Pillow-1.7.8# python3 setup.py install
Traceback (most recent call last):
  File "setup.py", line 10, in <module>
    from setuptools import Extension, setup, find_packages
ImportError: No module named setuptools

UPDATE 2

After i have run this terminal command

在我运行这个终端命令之后。

sudo apt-get install python3-setuptools

i can build the setup.py already,but error message at last.

我可以建立设置。已经是py了,但最后还是错误消息。

root@sys:~/Downloads/Pillow-1.7.8# python3 setup.py build
running build
running build_py
running build_ext
Traceback (most recent call last):
  File "setup.py", line 469, in <module>
    scripts=glob.glob("Scripts/pil*.py"),
  File "/usr/lib/python3.2/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/lib/python3.2/distutils/dist.py", line 917, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.2/distutils/dist.py", line 936, in run_command
    cmd_obj.run()
  File "/usr/lib/python3.2/distutils/command/build.py", line 126, in run
    self.run_command(cmd_name)
  File "/usr/lib/python3.2/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python3.2/distutils/dist.py", line 936, in run_command
    cmd_obj.run()
  File "/usr/lib/python3.2/distutils/command/build_ext.py", line 344, in run
    self.build_extensions()
  File "setup.py", line 127, in build_extensions
    self.add_multiarch_paths()
  File "setup.py", line 439, in add_multiarch_paths
    '/usr/lib/' + multiarch_path_component)
TypeError: Can't convert 'bytes' object to str implicitly

UPDATE 3

Error message when use https://github.com/python-imaging/Pillow this file

当使用https://github.com/pythonimaging/pillow这个文件时出错信息。

root@sys:~/Pillow-master# dir
COPYING              Images          map.c       selftest.py
decode.c             _imaging.c      outline.c   setup.py
display.c            _imagingcms.c   path.c      test
docs                 _imagingft.c    PIL         Tests
encode.c             _imagingmath.c  py3.h       Tk
github-comments.txt  _imagingtk.c    README.rst  tox.ini
github-issues.txt    libImaging      Sane
github-watchers.txt  MANIFEST.in     Scripts
root@sys:~/Pillow-master# python3 setup.py build
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.2
creating build/lib.linux-x86_64-3.2/PIL
copying PIL/IcnsImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/PpmImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ContainerIO.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImageMath.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/SunImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/BufrStubImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/GimpGradientFile.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImageGL.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/JpegImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImageDraw.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/PngImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/TiffTags.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/PcfFontFile.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImagePalette.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/IcoImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/PSDraw.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/CurImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImageEnhance.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImageDraw2.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/Image.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/FpxImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImageWin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/WalImageFile.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImageGrab.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/PcdImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/OleFileIO.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/SgiImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImageFilter.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/FitsStubImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/XbmImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/GifImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImageStat.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImageFileIO.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImageChops.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/McIdasImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/EpsImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImageOps.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/__init__.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/Hdf5StubImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/MpegImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/PaletteFile.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/TarIO.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/FontFile.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/GimpPaletteFile.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ArgImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/BmpImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/PalmImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/GribStubImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/BdfFontFile.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ExifTags.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImageShow.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/DcxImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/MspImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/GdImageFile.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/XVThumbImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/GbrImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImageSequence.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/PcxImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImageTransform.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/XpmImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/MicImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImageFile.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImagePath.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/_binary.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/TgaImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImageTk.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImageCms.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImageMode.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/WmfImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/PsdImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/IptcImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImageFont.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/PixarImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/TiffImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/FliImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImtImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImageQt.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/PdfImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/ImageColor.py -> build/lib.linux-x86_64-3.2/PIL
copying PIL/SpiderImagePlugin.py -> build/lib.linux-x86_64-3.2/PIL
running build_ext
building '_imaging' extension
creating build/temp.linux-x86_64-3.2/libImaging
gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -fPIC -DHAVE_LIBJPEG -DHAVE_LIBZ -I/usr/include/freetype2 -IlibImaging -I/usr/include -I/usr/local/include -I/usr/include/python3.2mu -I/usr/include/x86_64-linux-gnu -c _imaging.c -o build/temp.linux-x86_64-3.2/_imaging.o
_imaging.c:75:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1

SOLVED

follow the step to install

按照步骤安装。

sudo aptitude install python3-setuptools
sudo easy_install3 pip
sudo apt-get install python3-dev
# download Pillow's master.zip
wget https://github.com/python-imaging/Pillow/archive/master.zip
sudo unzip master.zip
python3 setup.py build
python3 setup.py install

DONE!

完成了!

3 个解决方案

#1


2  

[(I seem to be making a mess of things in the comments, sorry about that, here's a better version)

(我似乎在评论中把事情搞得一团糟,很抱歉,这里有一个更好的版本)

The error clearly states that you're missing setuptools for python3. The package python3-setuptools should take care of that (run sudo apt-get install python3-setuptools).

错误清楚地指出,您正在丢失python3的setuptools。包python3-setuptools应该处理这个(运行sudo apt-get安装python3-setuptools)。

Then, as you noticed, default PIL doesn't work for python3. The current state of the github master of Pillow does, however. That will install by using python3 setup.py build and sudo python3 setup.py install.

然后,正如您注意到的,默认的PIL不适合python3。然而,github的枕头主人现在的状态是这样的。这将通过使用python3设置来安装。py构建和sudo python3设置。py安装。

#2


1  

Your instructions are too long and not entirely scripted, these are better (same platform — recent Debian/Ubuntu):

你的指令太长,而且没有完全照本写,这些都是更好的(同样的平台——最近的Debian/Ubuntu):

sudo aptitude install python3-pip git
pip-3.2 install --user git+https://github.com/python-imaging/Pillow

#3


0  

for those here to get scipy working with PIL (Pillow), on python3

对于那些在python3上用PIL(枕头)工作的人。

After executing the receipe Chin Ye above, I was then able to get scipy.misc.imread and scipy.misc.imsave to be available when issuing import scipy.misc by tweaking two lines in the file:

在执行完上述的收据后,我就能得到scipy.misc。imread scipy.misc。当发布导入scipy时,可以使用imsave。通过对文件中的两行进行调整:

/usr/lib/python3/dist-packages/scipy/misc/pilutil.py

/usr/lib/python3/dist-packages / scipy / misc / pilutil.py

in that file, replace the lines:

在该文件中,替换这些行:

import Image
import ImageFilter

to be:

是:

from PIL import Image
from PIL import ImageFilter

the imports in scipy.misc.__init__ then worked to allow the contents of pilutil.py to work (esp image io - from numpy array formats)

scipy.misc进口。然后,开始工作,允许pilutil的内容。py to work (esp图像io -从numpy数组格式)

this was for Ubuntu 12.04 LTS, scipy.__version__ 0.9.0

这是Ubuntu 12.04 LTS, scipy。__version__ 0.9.0

(for more information on the tweak itself, see the docs for the Pillow implementaion of PIL)

(关于调整本身的更多信息,请参阅PIL的枕头实现者的文档)

#1


2  

[(I seem to be making a mess of things in the comments, sorry about that, here's a better version)

(我似乎在评论中把事情搞得一团糟,很抱歉,这里有一个更好的版本)

The error clearly states that you're missing setuptools for python3. The package python3-setuptools should take care of that (run sudo apt-get install python3-setuptools).

错误清楚地指出,您正在丢失python3的setuptools。包python3-setuptools应该处理这个(运行sudo apt-get安装python3-setuptools)。

Then, as you noticed, default PIL doesn't work for python3. The current state of the github master of Pillow does, however. That will install by using python3 setup.py build and sudo python3 setup.py install.

然后,正如您注意到的,默认的PIL不适合python3。然而,github的枕头主人现在的状态是这样的。这将通过使用python3设置来安装。py构建和sudo python3设置。py安装。

#2


1  

Your instructions are too long and not entirely scripted, these are better (same platform — recent Debian/Ubuntu):

你的指令太长,而且没有完全照本写,这些都是更好的(同样的平台——最近的Debian/Ubuntu):

sudo aptitude install python3-pip git
pip-3.2 install --user git+https://github.com/python-imaging/Pillow

#3


0  

for those here to get scipy working with PIL (Pillow), on python3

对于那些在python3上用PIL(枕头)工作的人。

After executing the receipe Chin Ye above, I was then able to get scipy.misc.imread and scipy.misc.imsave to be available when issuing import scipy.misc by tweaking two lines in the file:

在执行完上述的收据后,我就能得到scipy.misc。imread scipy.misc。当发布导入scipy时,可以使用imsave。通过对文件中的两行进行调整:

/usr/lib/python3/dist-packages/scipy/misc/pilutil.py

/usr/lib/python3/dist-packages / scipy / misc / pilutil.py

in that file, replace the lines:

在该文件中,替换这些行:

import Image
import ImageFilter

to be:

是:

from PIL import Image
from PIL import ImageFilter

the imports in scipy.misc.__init__ then worked to allow the contents of pilutil.py to work (esp image io - from numpy array formats)

scipy.misc进口。然后,开始工作,允许pilutil的内容。py to work (esp图像io -从numpy数组格式)

this was for Ubuntu 12.04 LTS, scipy.__version__ 0.9.0

这是Ubuntu 12.04 LTS, scipy。__version__ 0.9.0

(for more information on the tweak itself, see the docs for the Pillow implementaion of PIL)

(关于调整本身的更多信息,请参阅PIL的枕头实现者的文档)