0

I'm trying to import PIL with monkeyrunner

import re
import math
import os
from PIL import Image
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
import commands
import sys

but I keep getting an error:

ImportError: No module named PIL

I know it is something with monkeyrunner because I can successfully import PIL when running a regular python script. I was reading around and maybe this had something to do with PYTHONPATH? I am not sure what I need to do to allow these other module imports with monkeyrunner.

I am running on windows.

Micro
  • 10,303
  • 14
  • 82
  • 120
  • Give **[AndroidViewClient/culebra](https://github.com/dtmilano/AndroidViewClient)** a try. It's 100% python so you won't have those problems. – Diego Torres Milano May 29 '14 at 03:07
  • @dtmilano so where would I put the PIL import Image or any other imports when using AndroidViewClient? After the `from com.dtmilano.android.viewclient import ViewClient`? – Micro May 29 '14 at 15:57
  • I guess it shouldn't matter – Diego Torres Milano May 29 '14 at 16:22
  • @dtmilano Just having trouble importing things. Does AndroidViewClient allow you to use the monkeyrunner classes like 'device = MonkeyRunner.waitForConnection()` or `device.touch(253,340, 'DOWN_AND_UP')`? So I don't have to re-write everything with the ViewClient class? I am looking to just be able to use PIL and the monkeyrunner classes together. (then later expand and use ViewClient, but most of my code is written in monkeyrunner classes already) – Micro May 29 '14 at 16:31
  • Most of the scripts will run with no or small changes. – Diego Torres Milano May 29 '14 at 17:27

1 Answers1

1

You should install PIL for Python 2.5 under '/Library/Python/2.5/site-packages/'. Because MonkeyRunner uses Jython 2.5, based on Python 2.5.

Then add the path of PIL to Jython's path.

import sys
sys.path.append('/Library/Python/2.5/site-packages/your-PIL')

See How I install various Python libraries in Jython? for details.

Community
  • 1
  • 1
loveisbug
  • 411
  • 5
  • 9