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?
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 )
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