Last active
December 11, 2015 14:29
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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 |
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
.
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
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.