package/bin/exec_anaconda.py
def exec_anaconda():
    """Re-execute the current Python script using the Anaconda Python
    interpreter included with Splunk_SA_Scientific_Python.

    After executing this function, you can safely import the Python
    libraries included in Splunk_SA_Scientific_Python (e.g. numpy).

    Canonical usage is to put the following at the *top* of your
    Python script (before any other imports):

       import exec_anaconda
       exec_anaconda.exec_anaconda()

       # Your other imports should now work.
       import numpy as np
       import pandas as pd
       ...
    """
    if PSC_PATH_PREFIX in sys.executable:
        from imp import reload

        fix_sys_path()

        reload(json)
        reload(os)
        reload(platform)
        reload(stat)
        reload(subprocess)
        reload(sys)
        return

    check_python_version()

    system = (platform.system(), platform.machine())
    if system not in SUPPORTED_SYSTEMS:
        raise Exception('Unsupported platform: %s %s' % (system))

    sa_scipy = '%s%s' % (PSC_PATH_PREFIX, SUPPORTED_SYSTEMS[system])

    sa_path = os.path.join(get_apps_path(), sa_scipy)
    if not os.path.isdir(sa_path):
        raise Exception('Failed to find Python for Scientific Computing Add-on (%s)' % sa_scipy)

    system_path = os.path.join(sa_path, 'bin', '%s' % (SUPPORTED_SYSTEMS[system]))

    if system[0] == 'Windows':
        python_path = os.path.join(system_path, 'python.exe')
        # MLA-564: Windows need the DLLs to be in the PATH
        dllpath = os.path.join(system_path, 'Library', 'bin')
        pathsep = os.pathsep if 'PATH' in os.environ else ''
        os.environ['PATH'] = os.environ.get('PATH', '') + pathsep + dllpath
    else:
        python_path = os.path.join(system_path, 'bin', 'python')

    # MLA-996: Unset PYTHONHOME
    # XXX: After migration to Python3 PYTHONPATH is not set anymore so this will
    # be unnecessary. SPL-170875
    os.environ.pop('PYTHONHOME', None)

    # Ensure that execute bit is set on <system_path>/bin/python
    if system[0] != 'Windows':
        mode = os.stat(python_path).st_mode
        os.chmod(python_path, mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)

    print('INFO Running %s' % " ".join([python_path] + sys.argv), sys.stderr)
    sys.stderr.flush()

    # In Quake and later PYTHONPATH is removed or not set.
    # So after shelling into PSC Python interpreter will lose
    # information about what Splunk core's Python path is. So we
    # stash it into an environment variable to retrieve it after
    # switching into conda.
    os.environ['SPLUNK_CORE_PYTHONPATH'] = json.dumps(sys.path)

    try:
        if system[0] == "Windows":
            os.environ['MKL_NUM_THREADS'] = '1'
            # os.exec* broken on Windows: http://bugs.python.org/issue19066
            subprocess.check_call([python_path] + sys.argv)
            os._exit(0)
        else:
            os.environ['VECLIB_MAXIMUM_THREADS'] = '1'
            os.environ['OPENBLAS_NUM_THREADS'] = '1'
            os.execl(python_path, python_path, *sys.argv)
    except Exception:
        traceback.print_exc(None, sys.stderr)
        sys.stderr.flush()
        time.sleep(0.1)
        raise RuntimeError(
            'Error encountered while loading Python for Scientific Computing, see search.log.'
        )
Re-execute the current Python script using the Anaconda Python
    interpreter included with Splunk_SA_Scientific_Python.

    After executing this function, you can safely import the Python
    libraries included in Splunk_SA_Scientific_Python (e.g. numpy).

    Canonical usage is to put the following at the *top* of your
    Python script (before any other imports):

       import exec_anaconda
       exec_anaconda.exec_anaconda()

       # Your other imports should now work.
       import numpy as np
       import pandas as pd
       ...
    
Re-execute the current Python script using the Anaconda Python
interpreter included with Splunk_SA_Scientific_Python.

After executing this function, you can safely import the Python
libraries included in Splunk_SA_Scientific_Python .

Canonical usage is to put the following at the *top* of your
Python script (before any other imports).



Your other imports should now work.
import numpy as np
import pandas as pd
Re - execute the current Python script using the Anaconda Python interpreter included with Splunk_SA_Scientific_Python . After executing this function you can safely import the Python libraries included in Splunk_SA_Scientific_Python . Canonical usage is to put the following at the * top * of your Python script ( before any other imports ) . Your other imports should now work . import numpy as np import pandas as pd
def exec_anaconda():
    if PSC_PATH_PREFIX in sys.executable:
        from imp import reload
        fix_sys_path()
        reload(json)
        reload(os)
        reload(platform)
        reload(stat)
        reload(subprocess)
        reload(sys)
        return
    check_python_version()
    system = (platform.system(), platform.machine())
    if system not in SUPPORTED_SYSTEMS:
        raise Exception('Unsupported platform: %s %s' % (system))
    sa_scipy = '%s%s' % (PSC_PATH_PREFIX, SUPPORTED_SYSTEMS[system])
    sa_path = os.path.join(get_apps_path(), sa_scipy)
    if not os.path.isdir(sa_path):
        raise Exception('Failed to find Python for Scientific Computing Add-on (%s)' % sa_scipy)
    system_path = os.path.join(sa_path, 'bin', '%s' % (SUPPORTED_SYSTEMS[system]))
    if system[0] == 'Windows':
        python_path = os.path.join(system_path, 'python.exe')
        dllpath = os.path.join(system_path, 'Library', 'bin')
        pathsep = os.pathsep if 'PATH' in os.environ else ''
        os.environ['PATH'] = os.environ.get('PATH', '') + pathsep + dllpath
    else:
        python_path = os.path.join(system_path, 'bin', 'python')
    os.environ.pop('PYTHONHOME', None)
    if system[0] != 'Windows':
        mode = os.stat(python_path).st_mode
        os.chmod(python_path, mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
    print('INFO Running %s' % " ".join([python_path] + sys.argv), sys.stderr)
    sys.stderr.flush()
    os.environ['SPLUNK_CORE_PYTHONPATH'] = json.dumps(sys.path)
    try:
        if system[0] == "Windows":
            os.environ['MKL_NUM_THREADS'] = '1'
            subprocess.check_call([python_path] + sys.argv)
            os._exit(0)
        else:
            os.environ['VECLIB_MAXIMUM_THREADS'] = '1'
            os.environ['OPENBLAS_NUM_THREADS'] = '1'
            os.execl(python_path, python_path, *sys.argv)
    except Exception:
        traceback.print_exc(None, sys.stderr)
        sys.stderr.flush()
        time.sleep(0.1)
        raise RuntimeError(
            'Error encountered while loading Python for Scientific Computing, see search.log.'
        )
def exec_anaconda ( ) : if PSC_PATH_PREFIX in sys . executable : from imp import reload fix_sys_path ( ) reload ( json ) reload ( os ) reload ( platform ) reload ( stat ) reload ( subprocess ) reload ( sys ) return check_python_version ( ) system = ( platform . system ( ) , platform . machine ( ) ) if system not in SUPPORTED_SYSTEMS : raise Exception ( 'Unsupported platform: %s %s' % ( system ) ) sa_scipy = '%s%s' % ( PSC_PATH_PREFIX , SUPPORTED_SYSTEMS [ system ] ) sa_path = os . path . join ( get_apps_path ( ) , sa_scipy ) if not os . path . isdir ( sa_path ) : raise Exception ( 'Failed to find Python for Scientific Computing Add-on (%s)' % sa_scipy ) system_path = os . path . join ( sa_path , 'bin' , '%s' % ( SUPPORTED_SYSTEMS [ system ] ) ) if system [ 0 ] == 'Windows' : python_path = os . path . join ( system_path , 'python.exe' ) dllpath = os . path . join ( system_path , 'Library' , 'bin' ) pathsep = os . pathsep if 'PATH' in os . environ else '' os . environ [ 'PATH' ] = os . environ . get ( 'PATH' , '' ) + pathsep + dllpath else : python_path = os . path . join ( system_path , 'bin' , 'python' ) os . environ . pop ( 'PYTHONHOME' , None ) if system [ 0 ] != 'Windows' : mode = os . stat ( python_path ) . st_mode os . chmod ( python_path , mode | stat . S_IXUSR | stat . S_IXGRP | stat . S_IXOTH ) print ( 'INFO Running %s' % " " . join ( [ python_path ] + sys . argv ) , sys . stderr ) sys . stderr . flush ( ) os . environ [ 'SPLUNK_CORE_PYTHONPATH' ] = json . dumps ( sys . path ) try : if system [ 0 ] == "Windows" : os . environ [ 'MKL_NUM_THREADS' ] = '1' subprocess . check_call ( [ python_path ] + sys . argv ) os . _exit ( 0 ) else : os . environ [ 'VECLIB_MAXIMUM_THREADS' ] = '1' os . environ [ 'OPENBLAS_NUM_THREADS' ] = '1' os . execl ( python_path , python_path , * sys . argv ) except Exception : traceback . print_exc ( None , sys . stderr ) sys . stderr . flush ( ) time . sleep ( 0.1 ) raise RuntimeError ( 'Error encountered while loading Python for Scientific Computing, see search.log.' )
Re-execute the current Python script using the Anaconda Python
interpreter included with Splunk_SA_Scientific_Python.
Re - execute the current Python script using the Anaconda Python interpreter included with Splunk_SA_Scientific_Python .
"""Re-execute the current Python script using the Anaconda Python
    interpreter included with Splunk_SA_Scientific_Python.

    After executing this function, you can safely import the Python
    libraries included in Splunk_SA_Scientific_Python (e.g. numpy).

    Canonical usage is to put the following at the *top* of your
    Python script (before any other imports):

       import exec_anaconda
       exec_anaconda.exec_anaconda()

       # Your other imports should now work.
       import numpy as np
       import pandas as pd
       ...
    """ # MLA-564: Windows need the DLLs to be in the PATH # MLA-996: Unset PYTHONHOME # XXX: After migration to Python3 PYTHONPATH is not set anymore so this will # be unnecessary. SPL-170875 # Ensure that execute bit is set on <system_path>/bin/python # In Quake and later PYTHONPATH is removed or not set. # So after shelling into PSC Python interpreter will lose # information about what Splunk core's Python path is. So we # stash it into an environment variable to retrieve it after # switching into conda. # os.exec* broken on Windows: http://bugs.python.org/issue19066