Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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.

P/S: I have tried the following:

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

UPDATE:

Using the python3 command results in an error message.

Example 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:

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.

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

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!

like image 865
John Walker Avatar asked Feb 21 '13 12:02

John Walker


People also ask

Does PIL support Python 3?

PIL is an abbreviation of Python Imaging Library and it adds image processing to Python. In 2011, PIL has been discontinued—its unofficial successor framework Pillow for image processing is an actively maintained and user-friendly alternative for Python 3.

Is PIL and Pillow the same?

The Python Pillow library is a fork of an older library called PIL. PIL stands for Python Imaging Library, and it's the original library that enabled Python to deal with images. PIL was discontinued in 2011 and only supports Python 2.


2 Answers

[(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).

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.

like image 137
akaIDIOT Avatar answered Sep 29 '22 10:09

akaIDIOT


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

sudo aptitude install python3-pip git
pip-3.2 install --user git+https://github.com/python-imaging/Pillow
like image 36
Tobu Avatar answered Sep 29 '22 11:09

Tobu