Pillow Install Fails – Python 3.5.2

Hi everyone,

Pillow install fails

I ran into a bit of an issue trying to install Pillow on Raspbian with Python 3.5.2. The full error is below, but the solution was simply to install the following:

sudo apt-get install libjpeg8-dev
sudo pip3.5 install pillow

sudo pip3.5 install pillow
Collecting pillow
Using cached Pillow-4.3.0.tar.gz
Requirement already satisfied: olefile in /usr/local/lib/python3.5/site-packages (from pillow)
Installing collected packages: pillow
Running setup.py install for pillow … error
Complete output from command /usr/local/bin/python3.5 -u -c “import setuptools, tokenize;__file__=’/tmp/pip-build-inj0l_9q/pillow/setup.py’;f=getattr(tokenize, ‘open’, open)(__file__);code=f.read().replace(‘rn’, ‘n’);f.close();exec(compile(code, __file__, ‘exec’))” install –record /tmp/pip-xp_x4w_5-record/install-record.txt –single-version-externally-managed –compile:
running install
running build
running build_py
creating build
creating build/lib.linux-armv7l-3.5
creating build/lib.linux-armv7l-3.5/PIL
copying PIL/MicImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImageMath.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/WebPImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImagePath.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImageGrab.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/SunImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/__init__.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImageEnhance.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImageMorph.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/XpmImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/EpsImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/FtexImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/WmfImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/FitsStubImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImageDraw2.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/IptcImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/_binary.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/MpoImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/Hdf5StubImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/Image.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/MspImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImageWin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/GimpPaletteFile.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImageTk.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/PSDraw.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/McIdasImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/SgiImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImageStat.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImageChops.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/PdfImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/features.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/PcfFontFile.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/PcxImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImageOps.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImagePalette.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/TgaImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImageSequence.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/_util.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/TiffTags.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/BmpImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/DdsImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ExifTags.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/PyAccess.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/PpmImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImageCms.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/PaletteFile.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/XVThumbImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/IcoImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImageFilter.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImageFont.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/GifImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/GbrImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/XbmImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/PngImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/FontFile.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/IcnsImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/TiffImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/_tkinter_finder.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/DcxImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/OleFileIO.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/SpiderImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/JpegImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/GribStubImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/MpegImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/PalmImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/BdfFontFile.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/GimpGradientFile.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/PsdImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/WalImageFile.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImageFile.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/PcdImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/version.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/FpxImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImageQt.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/Jpeg2KImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImageDraw.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/GdImageFile.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ContainerIO.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/CurImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/FliImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImageMode.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/JpegPresets.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/PixarImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImageColor.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/BufrStubImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImageTransform.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImageShow.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/TarIO.py -> build/lib.linux-armv7l-3.5/PIL
copying PIL/ImtImagePlugin.py -> build/lib.linux-armv7l-3.5/PIL
running egg_info
writing dependency_links to Pillow.egg-info/dependency_links.txt
writing requirements to Pillow.egg-info/requires.txt
writing top-level names to Pillow.egg-info/top_level.txt
writing Pillow.egg-info/PKG-INFO
warning: manifest_maker: standard file ‘-c’ not found

reading manifest file ‘Pillow.egg-info/SOURCES.txt’
reading manifest template ‘MANIFEST.in’
warning: no files found matching ‘*.sh’
no previously-included directories found matching ‘docs/_static’
warning: no previously-included files found matching ‘.coveragerc’
warning: no previously-included files found matching ‘codecov.yml’
warning: no previously-included files found matching ‘.editorconfig’
warning: no previously-included files found matching ‘.landscape.yaml’
warning: no previously-included files found matching ‘.travis’
warning: no previously-included files found matching ‘.travis/*’
warning: no previously-included files found matching ‘appveyor.yml’
warning: no previously-included files found matching ‘build_children.sh’
warning: no previously-included files found matching ‘tox.ini’
warning: no previously-included files matching ‘.git*’ found anywhere in distribution
warning: no previously-included files matching ‘*.pyc’ found anywhere in distribution
warning: no previously-included files matching ‘*.so’ found anywhere in distribution
writing manifest file ‘Pillow.egg-info/SOURCES.txt’
running build_ext

The headers or library files could not be found for jpeg,
a required dependency when compiling Pillow from source.

Please see the install instructions at:
https://pillow.readthedocs.io/en/latest/installation.html

Traceback (most recent call last):
File “/tmp/pip-build-inj0l_9q/pillow/setup.py”, line 787, in
zip_safe=not (debug_build() or PLATFORM_MINGW), )
File “/usr/local/lib/python3.5/distutils/core.py”, line 148, in setup
dist.run_commands()
File “/usr/local/lib/python3.5/distutils/dist.py”, line 955, in run_commands
self.run_command(cmd)
File “/usr/local/lib/python3.5/distutils/dist.py”, line 974, in run_command
cmd_obj.run()
File “/usr/local/lib/python3.5/site-packages/setuptools/command/install.py”, line 61, in run
return orig.install.run(self)
File “/usr/local/lib/python3.5/distutils/command/install.py”, line 539, in run
self.run_command(‘build’)
File “/usr/local/lib/python3.5/distutils/cmd.py”, line 313, in run_command
self.distribution.run_command(command)
File “/usr/local/lib/python3.5/distutils/dist.py”, line 974, in run_command
cmd_obj.run()
File “/usr/local/lib/python3.5/distutils/command/build.py”, line 135, in run
self.run_command(cmd_name)
File “/usr/local/lib/python3.5/distutils/cmd.py”, line 313, in run_command
self.distribution.run_command(command)
File “/usr/local/lib/python3.5/distutils/dist.py”, line 974, in run_command
cmd_obj.run()
File “/usr/local/lib/python3.5/distutils/command/build_ext.py”, line 338, in run
self.build_extensions()
File “/tmp/pip-build-inj0l_9q/pillow/setup.py”, line 577, in build_extensions
raise RequiredDependencyException(f)
__main__.RequiredDependencyException: jpeg

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “”, line 1, in
File “/tmp/pip-build-inj0l_9q/pillow/setup.py”, line 799, in
raise RequiredDependencyException(msg)
__main__.RequiredDependencyException:

The headers or library files could not be found for jpeg,
a required dependency when compiling Pillow from source.

Please see the install instructions at:
https://pillow.readthedocs.io/en/latest/installation.html

—————————————-
Command “/usr/local/bin/python3.5 -u -c “import setuptools, tokenize;__file__=’/tmp/pip-build-inj0l_9q/pillow/setup.py’;f=getattr(tokenize, ‘open’, open)(__file__);code=f.read().replace(‘rn’, ‘n’);f.close();exec(compile(code, __file__, ‘exec’))” install –record /tmp/pip-xp_x4w_5-record/install-record.txt –single-version-externally-managed –compile” failed with error code 1 in /tmp/pip-build-inj0l_9q/pillow/

Thanks to the comment on the following Stackoverflow post for the solution: https://stackoverflow.com/a/34631976/522859

Check Tensorflow Version – Raspbian

Hey everyone,

Just a quick post on how to check the Tensorflow version on Raspbian with a one-liner (assumes Python 3.x):


python3 -c 'import tensorflow as tf; print(tf.__version__)'

Check out this Stackoverflow post for more info: https://stackoverflow.com/a/38549357/522859

AttributeError: ‘dict’ object has no attribute ‘iteritems’ – Python

Hey everyone,

Just running through object detection samples for Tensorflow and I encountered the following error:

Sample: https://github.com/GoogleCloudPlatform/tensorflow-object-detection-example

AttributeError: ‘dict’ object has no attribute ‘iteritems’

The issue seems to be that the sample hasn’t been made compatible with Python 3.x. Simply make the following change and it should work:


# Original
for cls, new_image in new_images.iteritems():

# Changed
for cls, new_image in new_images.items():

Thanks to the following StackOverflow post: https://stackoverflow.com/a/30418498/522859

Converting proto files to .py on Windows – Tensorflow

Hey everyone,

Ran into a bit of an issue today with Tensorflow:

ImportError: cannot import name preprocessor_pb2

Turned out that I hadn’t run some of the installing steps. I needed to use protoc to convert the proto directory files:

protoc object_detection/protos/preprocessor_pb2.proto --python_out=.

This turned out to be a bit of a headache as well, but thankfully a github post explained it all pretty well:

Here are the steps I followed to install it for windows:
(Prerequisite, you must have python, pip and)

Choose a Python release from here and download: Link here
– Extract the tar.gzor zip
– Open a cmd and pip install the following: pillow, lxml, jupyter, matplotlib
– Copy the protoc.exe from the protoc folder (you don’t need to do all the CMake steps you might have stumbled upon, it worked for me without them too) and paste it into your protos folder in the object detection directory.
– Run the protoc for each of those protos like “protoc object_detection/protos/*.proto –python_out=.”. . Note that you might encounter a problem with the paths and there’s two ways around that: Either move the protoc.exe two folders down or do the noobish thing that I did – copy the protos and paste them into a new directory inside the protos folder ‘object_detectionprotos’ so you would have a folder structure like’object_detectionprotosobject_detectionprotos’ (If it looks stupid but it works, it’s not stupid eh?) Note that *.proto might also not work and you might have to do each of them individually
– You are done. 🙂 Try to run something to see if you have any problems. You might have to install a manual version of numpyandscipy

GitHub Link: https://github.com/tensorflow/models/issues/1934

TensorFlow – KeyError: “The name ‘import/input’ refers to an Operation not in the graph.

Hey everyone,

Just another small error I’ve run into while testing out Tensorflow’s label image example (Tensorflow/tensorflow/examples/image_retraining/label_image.py):

KeyError: "The name 'import/input' refers to an Operation not in the graph.

This one thankfully doesn’t seem to be my fault. In label_image.py change the following lines:

# Line 78-79
input_layer = "input"
output_layer = "InceptionV3/Predictions/Reshape_1"

# Change to this
input_layer = "Mul"
output_layer = "final_result"

Once that’s done just rerun your script and it should all work. Thanks to the following post for the solution: https://github.com/tensorflow/tensorflow/issues/12736

Tensorflow – No such file or directory

Hey guys,

Just a quick post on how to resolve an error I came across while testing out tensorflow:

Traceback (most recent call last):
  File "C:UsersChris-PCDesktopimages-to-useattempt2tensorflowexampleslabel_imagelabel_image.py", line 112, in 
    graph = load_graph(model_file)
  File "C:UsersChris-PCDesktopimages-to-useattempt2tensorflowexampleslabel_imagelabel_image.py", line 30, in load_graph
    with open(model_file, "rb") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'tensorflow/examples/label_image/data/inception_v3_2016_08_28_frozen.pb'

All you need to do is download the following file and place it in the directory in the error message: https://storage.googleapis.com/download.tensorflow.org/models/inception_v3_2016_08_28_frozen.pb.tar.gz

Rename all files in a directory with Sequential Numbers

Hey guys,

Just a batch script I came across that allows you to rename all files in a directory with sequential numbers. Really handy for things like tensorflow. All you need to do is create a batch file in the directory containing the following:

@echo off
setlocal EnableDelayedExpansion
set i=0
for %%a in (*.jpg) do (
    set /a i+=1
    ren "%%a" "!i!.new"
)
ren *.new *.jpg

 

Thanks to this stackoverflow post: https://superuser.com/a/350633/124014