简体   繁体   English

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

[英]Install PIL in Ubuntu 12.04 Python 2.7 and Python 3.2

I am, using Ubuntu 12.04 server which by default has two versions of Python: 2.7 and 3.2. 我正在使用Ubuntu 12.04服务器,该服务器默认具有两个Python版本:2.7和3.2。 When I install PIL using the python setup.py install terminal command, the PIL will be installed with Python 2.7. 当我使用python setup.py install terminal命令安装PIL时,PIL将与Python 2.7一起安装。 How to install PIL with Python 3.2? 如何使用Python 3.2安装PIL? Because I'm using Python 3 to write my script. 因为我正在使用Python 3编写脚本。 If my Eclipse uses Python 2.7, PIL is successfully imported. 如果我的Eclipse使用Python 2.7,则PIL已成功导入。 But if I choose Python 3 as my Grammar language, PIL fails to import. 但是,如果我选择Python 3作为语法语言,则PIL无法导入。

P/S: I have tried the following: P / S:我尝试了以下方法:

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 更新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. 我已经可以建立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", 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 更新3

Error message when use https://github.com/python-imaging/Pillow this file 使用https://github.com/python-imaging/时出现错误消息

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! 完成!

[(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. 该错误明确表明您缺少python3的setuptools The package python3-setuptools should take care of that (run sudo apt-get install python3-setuptools ). 软件包python3-setuptools应该可以解决这个问题(运行sudo apt-get install python3-setuptools )。

Then, as you noticed, default PIL doesn't work for python3. 然后,正如您所注意到的,默认PIL对python3不起作用。 The current state of the github master of Pillow does, however. 但是Pillow的github大师的当前状态是这样。 That will install by using python3 setup.py build and sudo python3 setup.py install . 这将通过使用python3 setup.py buildsudo python3 setup.py install

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

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: 在执行上面的收据Chin Ye之后,然后通过在文件中调整两行,可以在发布import scipy.misc时使scipy.misc.imread和scipy.misc.imsave可用:

/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.__init__然后可以使pilutil.py的内容正常工作(特别是io图像pilutil.py来自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的Pillow实现的文档)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM