9

I searched a little bit but I couldn't find a tuto to use PIL with PyPy. According to PyPy's blog, PIL is supported.

  • I installed PIL with pip in my PYTHONPATH.
  • After the download, pip make 2 .pyd files: _imaging.pyd and _imagingmath.pyd.
  • After the install, I copied %PYTHONPATH%/lib/site-packages/PIL to my PyPy site-packages directory.
  • When I run my script (which uses PIL), it says it can't import the _imaging C module.

How should I do it ?

edit: I run this on Windows 7 x64 (python 2.7.1 32bits)

here is the traceback (pypy 1.4.1 windows binary):

Traceback (most recent call last):
  File "app_main.py", line 53, in run_toplevel
  File "tools\python\gen_images.py", line 52, in <module>
    main()
  File "tools\python\gen_images.py", line 44, in main
    image = Image.open(file)
  File "d:\pypy\site-packages\PIL\Image.py", line 1965, in open
    return factory(fp, filename)
  File "d:\pypy\site-packages\PIL\ImageFile.py", line 91, in __init__
    self._open()
  File "d:\pypy\site-packages\PIL\GifImagePlugin.py", line 97, in _open
    self.seek(0) # get ready to read first frame
  File "d:\pypy\site-packages\PIL\GifImagePlugin.py", line 152, in seek
    self.dispose = Image.core.fill("P", self.size,
  File "d:\pypy\site-packages\PIL\Image.py", line 37, in __getattr__
    raise ImportError("The _imaging C module is not installed")
ImportError: The _imaging C module is not installed
Syl
  • 2,733
  • 2
  • 17
  • 20
  • Can you show the failing error? It works just fine for me, with PyPy 1.4.1. (1.4.0 gave compile errors). – Lennart Regebro Feb 01 '11 at 16:07
  • 1
    apparently you compiled using CPython and hoped it would work just copied around. Don't do that. Compile using PyPy. – fijal Feb 01 '11 at 20:27
  • Do you mean PIL ? I installed it with pip and I configured mingw to build it (distutils.conf, compiler=mingw32). What should I do to build it with pypy ? – Syl Feb 01 '11 at 21:12
  • You need to run the install with the python executable that you install it for. So you need to run `pypy setup.py install`, or you need to install it with a pip that is installed for and run with pypy. Do you install pip for pypy? – Lennart Regebro Feb 02 '11 at 00:08
  • No, I'll do that. Thanks for the explanation. – Syl Feb 02 '11 at 07:23

2 Answers2

14

I did this:

$ /opt/pypy-1.4.1/bin/virtualenv test
$ cd test
$ bin/pip install PIL
...
--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version       1.1.7
platform      linux2 2.5.2 (e503e483e9ac, Dec 21 2010, 12:02:29)
              [PyPy 1.4.1]
--------------------------------------------------------------------
*** TKINTER support not available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
*** LITTLECMS support not available
--------------------------------------------------------------------
... 
$ bin/pypy
Python 2.5.2 (e503e483e9ac, Dec 21 2010, 12:02:29)
[PyPy 1.4.1] on linux2
>>>> import Image
>>>> im = Image.open('/path/to/file.jpg')
>>>> outfile = open('/path/to/file.png', 'wb')
>>>> im.save(outfile, 'png')

Worked like a charm. So do that. :)

Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251
  • yea sorry, I forgot to mention I'm trying to use it on Windows. – Syl Feb 01 '11 at 16:28
  • @Syl: AFAIK that should make no difference. – Lennart Regebro Feb 02 '11 at 00:05
  • This is so easy? I read that useing python external modules (PIL i c python api module) requires some external tool - **cpyext** which is very slow, and i'm not sure if it works well. – Robert Zaremba Feb 02 '11 at 18:48
  • @Robert: Well it worked, so obviously it is that easy. I didn't make any performance tests. :) – Lennart Regebro Feb 02 '11 at 20:44
  • What do I do if the ``pip install PIL`` command doesn't work? How do I prevent virtualenv from copying PIL? – Janus Troelsen Nov 26 '11 at 21:38
  • @user309483: You make it work. Or you ask a question about it. And please create an account, and please follow up on the question when you get answers. "How do I prevent virtualenv from copying PIL?" - It doesn't. – Lennart Regebro Nov 26 '11 at 22:23
  • Just as another datapoint: I tried installing PIL on to PyPy 1.9.0 on Mac OS X 10.8.2 using Pip 1.2.1 and when I tried to use it I got the same ImportError: The _imaging C module is not installed – pdc Jan 10 '13 at 19:26
  • Note that you need to have the build requirement for PIL for PyPy to be able to compile it successfully. If this is a Ubuntu-based machine, you need to have `apt-get install pypy-dev` in addition to other compilation requirements (e.g. libjpeg-dev if you want jpeg support, etc). Installing `python-dev` does not substitute `pypy-dev` – Lie Ryan Apr 05 '13 at 16:12
  • Worked for me, with two minor tweaks: using virtualenv's `--python` flag rather than using it in a special location, and installing `pillow` instead of `PIL`. – Solomon Ucko Dec 29 '21 at 16:43
3

I had no easy_install or pip installed, so followed the instructions in pip's documentation:

wget https://bootstrap.pypa.io/get-pip.py
pypy get-pip.py
pypy -m pip install pillow
Vajk Hermecz
  • 5,413
  • 2
  • 34
  • 25