Skip to main content
JR Moore
Participating Frequently
Jul 25, 2025 6:36 PM UTC
Question

PYTHON PACKAGE NOT FOUND

I have a python script that uses the "requests" package. When I run the Universe program that calls the function I get the "requests" package not found. I then created another python script that calls the python script that contains the "requests" package and it works when I call that script from Universe.  I must have something wrong in my path setting when coming from Universe and it cannot find the "requests" package. If I run the python script in Linux the program executes perfectly. If I invoke python from universe and import requests it works fine and finds the requests package. Both scripts are in the default location /XDEMO/PP.

u2.pth

/usr/ibm/bin
/usr/ibm/XDEMO/PP

Universe program:

 SUBROUTINE SUB.BASEVEHICLE(VEHID,VEHOUT)

      CMD = "REINIT.PYTHON OFF"

      EXECUTE CMD


      ModuleName = "callbaseveh"
      FuncName = "getbasevehinf"

      RESULT = PyCallFunction(ModuleName , FuncName, VEHID)

      IF @PYEXCEPTIONTYPE NE '' THEN
         CRT "EXCEPTION TYPE IS " :@PYEXCEPTIONTYPE
         CRT "EXCEPTION MESSAGE IS " :@PYEXCEPTIONMSG
         CRT "EXCEPTIONTRACEBACK IS " :@PYEXCEPTIONTRACEBACK
      END

      VEHOUT = RESULT
      RETURN

PYTHON CODE

import requests
import json

headers = {
'Key': 'xxxxxxxxxx',
}

def getdata(func, headers):
    url = 'https://urlgoeshere/' + func
    x = requests.get(url, params=headers)
    return x

def getbaseveh(basevehicleid):
    func = 'basevehicle'
    headers2 = {
        'BaseVehicleID' : basevehicleid,
    }
    headers.update(headers2)
    y = getaamdata(func, headers)
    basevehicle = y.json()
    return basevehicle
Thanks JR Moore

    1 reply

    John Jenkins
    Participating Frequently
    Jul 25, 2025 7:06 PM UTC

    I have a python script that uses the "requests" package. When I run the Universe program that calls the function I get the "requests" package not found. I then created another python script that calls the python script that contains the "requests" package and it works when I call that script from Universe.  I must have something wrong in my path setting when coming from Universe and it cannot find the "requests" package. If I run the python script in Linux the program executes perfectly. If I invoke python from universe and import requests it works fine and finds the requests package. Both scripts are in the default location /XDEMO/PP.

    u2.pth

    /usr/ibm/bin
    /usr/ibm/XDEMO/PP

    Universe program:

     SUBROUTINE SUB.BASEVEHICLE(VEHID,VEHOUT)

          CMD = "REINIT.PYTHON OFF"

          EXECUTE CMD


          ModuleName = "callbaseveh"
          FuncName = "getbasevehinf"

          RESULT = PyCallFunction(ModuleName , FuncName, VEHID)

          IF @PYEXCEPTIONTYPE NE '' THEN
             CRT "EXCEPTION TYPE IS " :@PYEXCEPTIONTYPE
             CRT "EXCEPTION MESSAGE IS " :@PYEXCEPTIONMSG
             CRT "EXCEPTIONTRACEBACK IS " :@PYEXCEPTIONTRACEBACK
          END

          VEHOUT = RESULT
          RETURN

    PYTHON CODE

    import requests
    import json

    headers = {
    'Key': 'xxxxxxxxxx',
    }

    def getdata(func, headers):
        url = 'https://urlgoeshere/' + func
        x = requests.get(url, params=headers)
        return x

    def getbaseveh(basevehicleid):
        func = 'basevehicle'
        headers2 = {
            'BaseVehicleID' : basevehicleid,
        }
        headers.update(headers2)
        y = getaamdata(func, headers)
        basevehicle = y.json()
        return basevehicle
    Thanks JR Moore

    JR Moore,

    I suspect either an error on the .pth file on the ,pth file in the wrong location (I've been caught out by mixed case myself on Windows for example - Windows file explorer lies). 

    You can also explicitly enumerate the module search path using

    import sys
    import pprint
    
    pprint.pprint(sys.path)


    Worth reviewing again:

    For the u2py extension module to be loadable in Python, the u2.pth file is placed in specific directories under the bundled Python installation directory.

    The following platforms and their associated paths are available for UniVerse:

    Platform Path
    AIX $UVHOME/python/lib/python#.#/site-packages
    Linux $UVHOME/python/lib/python#.#/site-packages
    Windows $UVHOMEpython

    The full path of $UVBIN is listed in the u2.pth file so that Python will load it into its search path when starting up. The XDEMO's PP directory path is included in the u2.pth file.

    Do not add any custom paths to the u2.pth file because this file is overwritten on upgrades.

    To add your directories containing Python modules to the module search path, place a unique path configuration file with the .pth extension in the appropriate path for your database and platform.

    Each path needed is included on a separate line in the custom .pth files.

    For example, on UniVerse and Windows in the $UVHOMEpython directory with a file called myprograms.pth, the paths will look like:
    
    c:U2AccountsSALESPP
    c:U2AccountsRENTALSPP
    
    

    The custom .pth files are not modified on upgrades.

    Remember: Directory paths and the .pth extensions are case-sensitive on Linux and AIX platforms.

    Regards

    JJ

    JJ