This discussion is archived
2 Replies Latest reply: Oct 29, 2012 2:39 AM by 970662 RSS

WLST offline script produces 'ImportError: no module named ...'

970662 Newbie
Currently Being Moderated
Dear All

Please help before I weep with frustration...this is sending me over the edge...

Our project has upgraded to WebLogic 11g & I have written WLST offline scripts to create a domain, upgrade to an ADF template, set datasoources, JMS, deploy applications, define security etc.
They work correctly & I am now in the process of updating them from my local development environment, to Windows & Linux production environments (for Maven integration, continuous build & test etc).
As such, I am tidying the POC scripts (parameterised the attributes for the domain into properties files, dynamic selection of number of managed servers, clusters etc etc).

& taking common functions out of all the scripts, & putting them in a commonFunctions.py file for reuse...
It is this change I cannot implement, as I am getting the dreaded 'no module named XXXXX' exception when it is executed.

I have read up on;
     Python / Jython relative vs absolute paths
     from path1.path2.A import function1, function2
     import path1.path2.A.function1...

I've changed the locations of the scripts so they all run in the same DIR, tried amending the PYTHON path, everything I can think of.
I'm fairly new(ish) to WLST (but not WebLogic) so I'm obviously missing something obvious, but god knows what it is.

Here's my current setup (I've replaced my parameterised values for the actual values for clarity);

- My start scripts runs from U:/scriptHome with;
WLST_HOME/wlst.cmd createDomain.py

- createDomain.py
execfile('U:/scriptHome/createAdfTemplateDomain.py)

- commonFunctions.py contains many functions, but one for example is;
def logger(logLine)
{
     print(logLine)
     logHandle.write(logLine)
     logHandle.flush()
     etc etc
}

- createAdfTemplateDomain.py
from commonFunctions import logger

Try & run the script & get;
ImportError: no module named commonFunctions

Environment;

- Windows XP
- WeLogic 11g installed
- Extended the domain (for ADF) [Oracle JFR - 11.1.1.0).  Hence oracle_common is now installed.
- Running WLST from C:/Oracle/Middleware/oracle_common/common/bin
- Python is preinstalled on my PC in C:/Progra~1/Python (version 2.4)
- Python Path is C:/Progra~1/Python;C:/Oracle/Middleware/oracle_common/common/bin
_ WLST_HOME (setup for my scripts) is C:/Oracle/Middleware/oracle_common/common/bin


Any ideas would be more than gratefully accepted as I'm currently a broken man.

Thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
  • 1. Re: WLST offline script produces 'ImportError: no module named ...'
    Kalyan Pasupuleti-Oracle Expert
    Currently Being Moderated
    Hi,

    you cannot import the value in this way.

    try this option while importing .py file.

    sys.path.append(".\\myscripts")
    print sys.path


    and check whether you get similar issue or not.


    eg:


    varholder.py

    thevariable=999


    callonvarholder.py

    import sys
    sys.path.append("C:\\Python\\varholder.py")
    import varholder.py

    num = '1'
    action.main(num)



    This should work for you.

    Regards,
    Kal
  • 2. Re: WLST offline script produces 'ImportError: no module named ...'
    970662 Newbie
    Currently Being Moderated
    Kal

    Thanks a lot. Your answer pointed me in the right direction.

    I tried using the sys.path.append('..') & from ..commonFunctions import etc commands but the WLST version 11g uses is based on Python 2.2.1 which doesn't support that syntax, which you obviously know.

    My initial script sets environment variables for the scripts to use, including the script DIR. So as you suggested, I used sys.path.append(os.environ["DOMAIN_SCRIPT_HOME"]), where DOMAIN_SCRIPT_HOME is U:/scriptHome.

    Which now works correctly.

    Thanks again for your reply.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points