Not Able to import PIL in Sikuli

邮差的信 提交于 2019-12-02 01:49:35

问题


I want to import PIL in Sikuli for doing that I have added the code below

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

import PIL
import Image

So it imported the above modules but when I am trying to import ImageFont, it's giving me the error below:

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

I am able to import PIL and Image and ImageFont successfully in Python scripts and code is running fine. Any idea how to fix this?


回答1:


The Sikuli IDE uses Jython so packages installed to your local Python version won't be able to be imported within the Sikuli IDE and Jython doesn't support c extensions as far I'm aware which PIL requires ( see http://bugs.jython.org/issue1388 ).

I think you would need to use a Java library, maybe something like ImageJ ( see http://fiji.sc/wiki/index.php/Jython_Scripting )




回答2:


Since the following (as I think valuable information) was rejected as an edit to the original question (my intention: people should see this in the first place), I put it as an answer now:

I want to add: Python modules can be imported in Jython/Sikuli scripts as long as they contain only Python code. There are many modules written for Python, that hold this condition (e.g. xlrd, xlwt). But as correctly mentioned: PIL contains C-based stuff and this can normally (exception JNI libs) not be loaded (hence the above error message, which is true, but might lead in the wrong direction).



来源:https://stackoverflow.com/questions/13488117/not-able-to-import-pil-in-sikuli

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