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

我使用Ubuntu 12.04服务器,默认情况下有两个版本的 Python:2.7和3.2.当我使用python setup.py install terminal命令安装PIL时,PIL将安装Python 2.7.如何使用Python 3.2安装PIL?因为我使用Python 3写我的脚本.如果我的Eclipse使用Python 2.7,PIL被成功导入.但是如果我选择Python 3作为我的语法语言,PIL无法导入.

P / S:我尝试了以下几点:

> Pillow PIL(Pillow-1.7.8.zip)
> Aspell PIL(PIL-1.1.7-py3-source.zip)

更新:

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

示例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

示例2:

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

更新2

我运行这个终端命令后

sudo apt-get install python3-setuptools

我可以建立setup.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",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

更新3

使用https://github.com/python-imaging/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

解决了

按照步骤安装

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!

[(我似乎在评论中弄乱了一些东西,对不起,这是一个更好的版本)

错误清楚地表明您缺少python3的setuptools.包python3-setuptools应该照顾(运行sudo apt-get install python3-setuptools).

那么,你注意到,默认的PIL不适用于python3. The current state of the github master of Pillow然而.这将通过使用python3 setup.py build和sudo python3 setup.py安装进行安装.

相关文章

文章浏览阅读2.3k次,点赞4次,收藏22次。最近安装了CARLA预...
文章浏览阅读6.3k次,点赞5次,收藏15次。在清华镜像中下载U...
文章浏览阅读5k次。linux环境, python3.7.问题描述: 安装...
文章浏览阅读4.2k次,点赞4次,收藏17次。要安装这个 standa...
文章浏览阅读894次,点赞51次,收藏31次。在安卓使用vscode主...