-
-
Save jphalip/4614527 to your computer and use it in GitHub Desktop.
%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 |
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.
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.
I thought Pillow would fix all that?