2

我想在 Sikuli 中导入 PIL 为此我添加了下面的代码

import sys
sys.path.append("C:\\Python27\Lib\site-packages")
sys.path.append("C:\\Python27\Lib\site-packages\PIL")

import PIL
import Image

所以它导入了上述模块,但是当我尝试导入 ImageFont 时,它给了我以下错误:

def getmask2(self, text, mode="", fill=Image.core.fill):
File "C:\Python27\Lib\site-packages\PIL\Image.py", line 39, in __getattr__
raise ImportError("The _imaging C module is not installed")
ImportError: The _imaging C module is not installed

我能够在 Python 脚本中成功导入 PIL 和 Image 和 ImageFont 并且代码运行良好。知道如何解决这个问题吗?

4

2 回答 2

3

Sikuli IDE 使用 Jython,因此安装到本地 Python 版本的包将无法在 Sikuli IDE 中导入,并且 Jython 不支持 c 扩展,据我所知 PIL 需要哪些(请参阅 http://bugs. jython.org/issue1388)。

我认为您需要使用 Java 库,可能类似于 ImageJ(请参阅 http://fiji.sc/wiki/index.php/Jython_Scripting

于 2012-11-21T23:03:18.737 回答
3

由于以下(我认为有价值的信息)被拒绝作为对原始问题的编辑(我的意图:人们应该首先看到这一点),我现在把它作为答案:

我想补充一点:只要 Python 模块只包含 Python 代码,就可以在 Jython/Sikuli 脚本中导入它们。有许多为 Python 编写的模块,它们都持有这种条件(例如 xlrd、xlwt)。但正如正确提到的:PIL 包含基于 C 的内容,并且通常(JNI 库除外)无法加载(因此上述错误消息是正确的,但可能会导致错误的方向)。

于 2012-12-21T08:38:09.230 回答