How to use PIL with PyPy?

泄露秘密 提交于 2019-12-04 11:20:45

问题


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

回答1:


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. :)




回答2:


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


来源:https://stackoverflow.com/questions/4864674/how-to-use-pil-with-pypy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!