login community faq
2
1

Hi!

How can I install PIL (Python Imaging Library) with truetype (libfreetype) support on my webfaction hosting account? Thank you.

asked Feb 04 '12 at 15:49

Andy's gravatar image

Andy
2114

edited Feb 04 '12 at 16:33


You can build PIL with support for JPEG, Freetype, etc, on our CentOS6 servers without building those libraries locally in your home directory, and without setting environment variables like LD_LIBRARY_PATH. Here are the steps:

First, download and extract the PIL tarball:

1
2
3
4
5
mkdir -p ~/src ~/lib/python2.7
cd ~/src
wget http://effbot.org/media/downloads/PIL-1.1.7.tar.gz
tar zxf PIL-1.1.7.tar.gz
cd PIL-1.1.7

Next, edit PIL's setup.py to set the library pointers as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# --------------------------------------------------------------------
# Library pointers.
#
# Use None to look for the libraries in well-known library locations.
# Use a string to specify a single directory, for both the library and
# the include files.  Use a tuple to specify separate directories:
# (libpath, includepath).  Examples:
#
# JPEG_ROOT = "/home/libraries/jpeg-6b"
# TIFF_ROOT = "/opt/tiff/lib", "/opt/tiff/include"
#
# If you have "lib" and "include" directories under a common parent,
# you can use the "libinclude" helper:
#
# TIFF_ROOT = libinclude("/opt/tiff")

TCL_ROOT = None
JPEG_ROOT = '/usr/lib64','/usr/include'
ZLIB_ROOT = '/lib64','/usr/include'
TIFF_ROOT = None
FREETYPE_ROOT = '/usr/lib64','/usr/include/freetype2/freetype'
LCMS_ROOT = None

Next, build PIL with the following command:

1
python2.7 setup.py build_ext -i

Next, run the test to confirm that the build was successful:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
$ python2.7 selftest.py
--------------------------------------------------------------------
PIL 1.1.7 TEST SUMMARY 
--------------------------------------------------------------------
Python modules loaded from ./PIL
Binary modules loaded from ./PIL
--------------------------------------------------------------------
--- PIL CORE support ok
--- TKINTER support ok
--- JPEG support ok
--- ZLIB (PNG/ZIP) support ok
--- FREETYPE2 support ok
--- LITTLECMS support ok
--------------------------------------------------------------------

Finally, install the library:

1
python2.7 setup.py install

You're done!

This answer is marked "community wiki".

answered Feb 12 '12 at 13:26

seanf's gravatar image

seanf ♦♦
55991220

edited Feb 29 '12 at 18:59

Currently if you import PIL using python2.7 on your account it is pulling in the shared version and not the installed one,

1
2
3
>>> import PIL
>>> print PIL
<module 'PIL' from '/usr/local/lib/python2.7/site-packages/PIL/__init__.py'>

This would account for why it is failing. I have ran

1
python2.7 setup.py install

On your account and now it imports correctly,

1
2
3
>>> import PIL
>>> print PIL
<module 'PIL' from '/home/username/lib/python2.7/PIL/__init__.pyc'>

However it now fails with,

1
2
3
4
>>> import _imaging
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: libjpeg.so.8: cannot open shared object file: No such file or directory

To solve this I did 2 things, 1 created a symbolic link to the real file,

1
[box@web315 lib]$ ln -s libjpeg.so.8.4.0 libjpeg.so.8

Than ran this line to load the lib path,

1
export LD_LIBRARY_PATH=~/lib

Selftest.py now runs but fails for missing files.

answered Feb 05 '12 at 03:07

johns's gravatar image

johns ♦♦
340427

edited Feb 05 '12 at 15:51

timg's gravatar image

timg ♦♦
4714

Thank you! I did something you said and it work fine now! i guess export LD_LIBRARY_PATH helped! Thanks!!!

(Feb 05 '12 at 03:44) Andy Andy's gravatar image

We have removed your account name from the answer.

(Feb 05 '12 at 15:51) timg ♦♦ timg's gravatar image

PIL is already installed on WebFaction server with TrueType support. You can test like this:

1
2
3
4
5
6
7
import Image, ImageFont, ImageDraw  
text = "TEST"  
image = Image.open("background.jpg")  
draw = ImageDraw.Draw(image)  
font = ImageFont.truetype("/usr/share/fonts/default/TrueType/georgia.ttf", 50, encoding='unic')  
draw.text((5, 5), text, font=font, fill="#aa0000")  
image.save("image.jpg")

answered Feb 04 '12 at 16:34

timg's gravatar image

timg ♦♦
4714

1

No luck:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
Traceback (most recent call last):
  File "a.py", line 5, in <module>
    font = ImageFont.truetype("/usr/share/fonts/default/TrueType/georgia.ttf", 50, encoding='unic')
  File "/usr/local/lib/python2.7/site-packages/PIL/ImageFont.py", line 218, in truetype
    return FreeTypeFont(filename, size, index, encoding)
  File "/usr/local/lib/python2.7/site-packages/PIL/ImageFont.py", line 134, in __init__
    self.font = core.getfont(file, size, index, encoding)
  File "/usr/local/lib/python2.7/site-packages/PIL/ImageFont.py", line 34, in __getattr__
    raise ImportError("The _imagingft C module is not installed")
ImportError: The _imagingft C module is not installed.

Any idea?

(Feb 04 '12 at 16:39) Andy Andy's gravatar image

Hi Andy,

Can you try this using the system Python2.7 now?

(Mar 21 '12 at 22:48) klynton ♦♦ klynton's gravatar image

A good set of build instructions can be found on stackoverflow,

For step 2 you should build freetype from source which is available here.

For step 3 you would use the path you defined in './configure --prefix='

answered Feb 04 '12 at 17:11

johns's gravatar image

johns ♦♦
340427

let me explain what i'm doing:

  1. downloaded freetype, libjpeg, libtiff, zlib.

  2. unpack them all.

  3. ./configure --prefix=$HOME && make && make install (for everyone).

  4. change setup.py of PIL (ROOT_*), also i added

    1
    2
    add_directory(library_dirs, "/$HOME/lib")
    add_directory(include_dirs, "/$HOME/include")
    

to 214 line.

I run python2.7 setup.py build_ext -i,

then python2.7 selftest.py and I get error:

1
*** The _imaging C module is not installed

what am i doing wrong? (noob in linux)

(Feb 04 '12 at 18:43) Andy Andy's gravatar image

Instead of using /$HOME/lib and /$HOME/include, can you try using the real paths, or else using os.environ['HOME']? Since setup.py is a python script and not bash, it won't necessarily expand these paths unless somehow it's re-set in a shell context. If this doesn't work, let us know and we'll be happy to investigate further.

(Feb 04 '12 at 18:59) ryans ♦♦ ryans's gravatar image

i did it too (/home/my_name/lib, home/my_name/include) but it still the same problem

(Feb 05 '12 at 02:27) Andy Andy's gravatar image

I'm having the same issue running on a RedHat installation on ASO shared hosting, running Python 2.7 with PIL 1.1.7. Here's what I get...


>>> from PIL import Image, ImageDraw, ImageFilter, ImageFont
>>> im = Image.new('RGB', (300,300), 'white')
>>> draw = ImageDraw.Draw(im)
>>> font = ImageFont.truetype('arial.ttf', 14)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/PIL/ImageFont.py", line 218, in truetype
    return FreeTypeFont(filename, size, index, encoding)
  File "/usr/local/lib/python2.7/site-packages/PIL/ImageFont.py", line 134, in __init__
    self.font = core.getfont(file, size, index, encoding)
  File "/usr/local/lib/python2.7/site-packages/PIL/ImageFont.py", line 34, in __getattr__
    raise ImportError("The _imagingft C module is not installed")
ImportError: The _imagingft C module is not installed
>>>
(Aug 29 '12 at 16:19) salsama salsama's gravatar image

I don't know if our instructions will work at ASO, but you're welcome to try them :)

(Aug 29 '12 at 16:54) seanf ♦♦ seanf's gravatar image

Installing PIL on a virtualenv (worked for me)

1 - pip install --no-install PIL (working on my virtualenv enviroment)

2 - edit the setup (inside the build directory of the virtual environment) in my case:

JPEG_ROOT = '/usr/lib64','/usr/include'

3 - pip install PIL

answered Oct 16 '12 at 14:04

aemb87's gravatar image

aemb87
1

Your answer
If you have an answer to the above question, then use the form below. Otherwise, use the appropriate 'add new comment' button above to post your feedback.
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×228
×8
×1

Asked: Feb 04 '12 at 15:49

Seen: 3,646 times

Last updated: Oct 16 '12 at 14:04

Plans & prices    Sign up    Why WebFaction?    Contact us    Affiliate program    Support    Legal    Jobs    Blog    Control panel login
Powered by OSQA
© Copyright 2003-2012 Swarma Limited - WebFaction is a service of Swarma Limited