简体   繁体   中英

Can not Import module from different package in monkeyrunner

I want to import a module Devices.py from package abc.devices, but it gives me an import error : No Module named abc. Here dev is a one package in which contains the module Devices.py. below is the code of my monkeyrunner file.

import os
import sys
import subprocess
import unittest
import commands
from ConfigParser import ConfigParser
from abc.Devices import Devices
dev = Devices()
dev.gDevice()

from com.android.monkeyrunner import MonkeyDevice, MonkeyRunner, MonkeyImage
from com.dtmilano.android.viewclient import ViewClient, View

monlyrunner is not reading PYTHONPATH so you have to do this before importing your modules (as ViewClient's examples do):

# PyDev sets PYTHONPATH, use it
try:
    for p in os.environ['PYTHONPATH'].split(':'):
        if not p in sys.path:
            sys.path.append(p)
except:
    pass

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM