2
1

Hi!

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

asked 04 Feb '12, 15:49

Andy's gravatar image

Andy
2114
accept rate: 0%

edited 04 Feb '12, 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:

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:

# --------------------------------------------------------------------
# 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:

python2.7 setup.py build_ext -i

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

$ 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:

python2.7 setup.py install

You're done!

link
This answer is marked "community wiki".

answered 12 Feb '12, 13:26

seanf's gravatar image

seanf ♦♦
8.0k1726
accept rate: 39%

edited 29 Feb '12, 18:59

Hi, I followed this howto and installed PIL. Now I want to uninstall it and install pillow instead. What should I do?

(18 Jun '13, 08:03) xpanta xpanta's gravatar image

Just delete the library from your ~/lib/python2.x directory, then install pillow with pip or easy_install.

(18 Jun '13, 17:25) seanf ♦♦ seanf's gravatar image

Thanks. There is a PIL library at /usr/local/lib/python2.7/site-packages/PIL/ and mine is at /home/xpanta/.virtualenvs/myproject/lib/python2.7/site-packages/PIL/, if I just uninstall my PIL and install pillow instead will it be fine? Strangely, there is no PIL directory in ~/lib/python2.7/, why?

(20 Jun '13, 03:16) xpanta xpanta's gravatar image

If you remove PIL from your virtualenv and replace it with Pillow, that should be fine.

As to why you don't have PIL in ~/lib/python2.7, if you installed it into your virtualenv, then it wouldn't be in ~/lib/python2.7.

(20 Jun '13, 11:55) seanf ♦♦ seanf's gravatar image

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

>>> 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

python2.7 setup.py install

On your account and now it imports correctly,

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

However it now fails with,

>>> 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,

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

Than ran this line to load the lib path,

export LD_LIBRARY_PATH=~/lib

Selftest.py now runs but fails for missing files.

link

answered 05 Feb '12, 03:07

johns's gravatar image

johns ♦♦
4.1k28
accept rate: 23%

edited 05 Feb '12, 15:51

timg's gravatar image

timg ♦♦
1.1k4

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

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

We have removed your account name from the answer.

(05 Feb '12, 15:51) timg ♦♦ timg'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

link

answered 16 Oct '12, 14:04

aemb87's gravatar image

aemb87
112
accept rate: 0%

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

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")
link

answered 04 Feb '12, 16:34

timg's gravatar image

timg ♦♦
1.1k4
accept rate: 28%

1

No luck:

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?

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

Hi Andy,

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

(21 Mar '12, 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='

link

answered 04 Feb '12, 17:11

johns's gravatar image

johns ♦♦
4.1k28
accept rate: 23%

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

    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:

*** The _imaging C module is not installed

what am i doing wrong? (noob in linux)

(04 Feb '12, 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.

(04 Feb '12, 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

(05 Feb '12, 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
>>>
(29 Aug '12, 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 :)

(29 Aug '12, 16:54) seanf ♦♦ seanf's gravatar image
Your answer
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

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×273
×10
×1

Asked: 04 Feb '12, 15:49

Seen: 7,597 times

Last updated: 20 Jun '13, 11:55

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