我搜索了一下,但找不到将 PIL 与 PyPy 结合使用的教程。根据 PyPy 的博客,支持 PIL。
- 我在我的 PYTHONPATH 中使用 pip 安装了 PIL。
- 下载后,pip 生成 2 个 .pyd 文件:_imaging.pyd 和 _imagingmath.pyd。
- 安装后,我将 %PYTHONPATH%/lib/site-packages/PIL 复制到我的 PyPy 站点包目录。
- 当我运行我的脚本(使用 PIL)时,它说它无法导入 _imaging C 模块。
我应该怎么做?
编辑: 我在 Windows 7 x64(python 2.7.1 32 位)上运行它
这是回溯(pypy 1.4.1 windows 二进制文件):
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
最佳答案
我这样做了:
$ /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')
工作起来很有魅力。所以这样做。 :)
关于python - 如何在 PyPy 中使用 PIL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4864674/