Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to check if python has already been initialized?

    Is there any variable or way to check if the python environment has already been loaded? (that is, the environment "python" has already been invoked (in the current stata session), which resulted in loading the shared object or dynamic library into memory? simply put, has the user already ran python/end in the current session?

    Thank you
    Last edited by jerome falken; 02 Sep 2020, 23:08.

  • #2
    The python query command will provide you the information you need; it is documented as part of the output of help python.
    Code:
    . python query
    ------------------------------------------------------------------------------------------------
        Python Settings
          set python_exec      /usr/bin/python
          set python_userpath  
    
        Python system information
          initialized          no
          version              2.7.10
          architecture         64-bit
          library path         /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.
    > 7/config/libpython2.7.dylib
    
    . python
    ----------------------------------------------- python (type end to exit) ----------------------
    >>> end
    ------------------------------------------------------------------------------------------------
    
    . python query
    ------------------------------------------------------------------------------------------------
        Python Settings
          set python_exec      /usr/bin/python
          set python_userpath  
    
        Python system information
          initialized          yes
          version              2.7.10
          architecture         64-bit
          library path         /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.
    > 7/config/libpython2.7.dylib
    
    . return list
    
    scalars:
            r(initialized) =  1
    
    macros:
               r(execpath) : "/usr/bin/python"
                r(version) : "2.7.10"
                   r(arch) : "64-bit"
                r(libpath) : "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/pytho.."
    .

    Comment


    • #3
      Perfect, I had not noticed the "initialized" setting.

      Comment

      Working...
      X