Skip to content

Instantly share code, notes, and snippets.

@jphalip
Last active December 11, 2015 14:29
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jphalip/4614527 to your computer and use it in GitHub Desktop.
Save jphalip/4614527 to your computer and use it in GitHub Desktop.
Bash script for a Chef recipe to install PIL with Zlib and Freetype support in a Vagrant Ubuntu 32bit box. I wish PIL offered a cleaner way of doing this other than having to modify its setup.py.
%w{libjpeg-dev libfreetype6-dev}.each do |pkg|
package pkg do
action :install
end
end
bash "Install PIL from source" do
user vagrant
group vagrant
code <<-EOH
. #{virtualenv_path}/bin/activate
pip install --no-install PIL==1.1.7
sed 's/ZLIB_ROOT = None/ZLIB_ROOT = ("\\/usr\\/lib\\/i386-linux-gnu", "\\/usr\\/include")/' #{virtualenv_path}/build/PIL/setup.py > #{virtualenv_path}/build/PIL/setup-modified.py ; mv #{virtualenv_path}/build/PIL/setup-modified.py #{virtualenv_path}/build/PIL/setup.py
sed 's/FREETYPE_ROOT = None/FREETYPE_ROOT = ("\\/usr\\/lib\\/i386-linux-gnu", "\\/usr\\/include\\/freetype2\\/freetype")/' #{virtualenv_path}/build/PIL/setup.py > #{virtualenv_path}/build/PIL/setup-modified.py ; mv #{virtualenv_path}/build/PIL/setup-modified.py #{virtualenv_path}/build/PIL/setup.py
python #{virtualenv_path}/build/PIL/setup.py install
EOH
not_if "test -d #{virtualenv_path}/lib/python2.7/site-packages/PIL"
end
@jezdez
Copy link

jezdez commented Jan 23, 2013

I thought Pillow would fix all that?

@jphalip
Copy link
Author

jphalip commented Jan 23, 2013

Thanks for the tip, Jannis. However, after a quick look it seems like you'd still need to manually modify Pillow's setup.py to enable zlib/freetype support.

@Aramgutang
Copy link

Instead of modifying setup.py, I usually create the symlinks that it needs, like so:

sudo ln -s /usr/lib/i386-linux-gnu/libjpeg.so /usr/lib/libjpeg.so
sudo ln -s /usr/lib/i386-linux-gnu/libz.so /usr/lib/libz.so
sudo ln -s /usr/lib/i386-linux-gnu/libfreetype.so /usr/lib/libfreetype.so

This has the benefit of being able to manually (re)install PIP (e.g. in a new virtualenv) on the machine in the future without any issues.

Note that depending on the distro you use, the libraries may be in directories other than /usr/lib/i386-linux-gnu/. If you have a 64-bit machine, they obviously won't be there. On CentOS/RedHat boxes, they can also be under /usr/lib64.

@jphalip
Copy link
Author

jphalip commented Jan 23, 2013

The symlink approach is quite neat, thanks. Also yes, the code above is only for a 32bit Ubuntu distro. The recipe could be improved by leveraging Chef's distro detection logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment