Rocket U2 | UniVerse & UniData

Expand all | Collapse all

UV Python Numpy Crash

Jump to Best Answer
  • 1.  UV Python Numpy Crash

    Posted 28 days ago
    I am having an issue I am hoping a bright mind around here can help me with. It seems that something in the Python interpreter is not cleaning up after itself after importing the NumPy library. In reality I was trying to use Pandas, but after some trial and error I think I have identified NumPy as the culprit.

    Replicating this is easy, after installing NumPy:

    From TCL:
    PYTHON
    import numpy
    quit()
    PYTHON
    import numpy

    Will crash every time. Same results from running the code from a python file.

    Having the ability to use NumPy would really enable some great functionality in UV and I would really like to get this working. Is anyone else having a similar issue?

    ------------------------------
    Nic Davidson
    Combined Transport
    ------------------------------


  • 2.  RE: UV Python Numpy Crash

    Posted 28 days ago
    Nic,

    When UniVerse exits the Python shell, it re-initializes the Python environment.  Some packages (numpy being one of them )  make changes that are not affected by the initialization and cause problems when imported again.

    Set the REINIT.PYTHON to OFF, and it should stop it from aborting.

    i.e.
    >REINIT.PYTHON OFF
    >PYTHON
    python> import numpy
    python> quit()
    >PYTHON
    python> import numpy
    python>

    Note that I plan to look a bit deeper into the abort, since it is a bit drastic. 


    ------------------------------
    Michael Rajkowski
    Rocket Software
    ------------------------------



  • 3.  RE: UV Python Numpy Crash
    Best Answer

    Posted 20 days ago

    Michael,

    After adding the command to VOC this worked perfectly! Thanks!

    For anyone else having the issue this is what I ended up doing to make life easier:

    Made a new (really tiny) module:

    u2_numpy
    -- __init__.py
    -- u2_numpy.py

    File contents:
    __init__.py:
    from .u2_numpy import *

    u2_numpy.py:
    # I made some changes to u2py and have my own version. This line could be just import u2py
    import u2py_new as u2py
    command = u2py.Command("REINIT.PYTHON OFF")
    command.run()
    import numpy

    In any module/file where I need to use numpy just do:

    import u2_numpy as numpy

    And you should be good to go! No issues for me as of yet.
    You would have to do this again if you wanted s different numpy type module (EX: Pandas). Potential way around this would be adding the u2py command to Numpy...but then you would have to "fix" it again on each package update.

    ​​

    ------------------------------
    Nic Davidson
    Combined Transport
    ------------------------------



  • 4.  RE: UV Python Numpy Crash

    Posted 20 days ago
    Nic,

    I like the setting of REINIT.PYTHON from Python.  I tend to decide if I want it on or off for an account and/or user and add the REINIT.PYTHON OFF to the LOGIN paragraph of the account in question, yet since there may be times you need to use a package that requires it off, you method looks promising.


    ------------------------------
    Michael Rajkowski
    Rocket Software
    ------------------------------