Skip to main content
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
------------------------------
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
------------------------------
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
------------------------------
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
------------------------------

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
------------------------------

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
------------------------------
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
------------------------------
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
------------------------------
This seemed like a useful way to solve the same problem that I am having with NumPy, but I don't seem to have that command on my Universe.

Verb "REINIT.PYTHON" is not in your VOC.

How do I get this very helpful feature?

Joe Miele

------------------------------
Joseph Miele
Self Registered
Clinton IA United States
------------------------------
This seemed like a useful way to solve the same problem that I am having with NumPy, but I don't seem to have that command on my Universe.

Verb "REINIT.PYTHON" is not in your VOC.

How do I get this very helpful feature?

Joe Miele

------------------------------
Joseph Miele
Self Registered
Clinton IA United States
------------------------------
I am not 100% sure as I appeared to just have it without trying when we updated to a UV version with Python. Mike will likely have more info,  but something really easy to try is to just add the VOC entry. Here is mine:

I will warn you that I have had some minor issues with the REINIT.PYTHON when running some code. For example, when logging, I would get an additional log entry for every time I reran the program without logging back in.
First time: Logs once
Second time: Logs twice
Third time: Logs three times
...and so on

HOWEVER! We recently updated to UV 12.X.X and on a couple of the modules I have tried (Numpy, XLRD) have both had the issues fixed without having to use REINIT.PYTHON There may be modules that will still need it...but thus far no issues.

------------------------------
Nic Davidson
Developer
Combined Transport Inc
Medford OR United States
------------------------------
I am not 100% sure as I appeared to just have it without trying when we updated to a UV version with Python. Mike will likely have more info,  but something really easy to try is to just add the VOC entry. Here is mine:

I will warn you that I have had some minor issues with the REINIT.PYTHON when running some code. For example, when logging, I would get an additional log entry for every time I reran the program without logging back in.
First time: Logs once
Second time: Logs twice
Third time: Logs three times
...and so on

HOWEVER! We recently updated to UV 12.X.X and on a couple of the modules I have tried (Numpy, XLRD) have both had the issues fixed without having to use REINIT.PYTHON There may be modules that will still need it...but thus far no issues.

------------------------------
Nic Davidson
Developer
Combined Transport Inc
Medford OR United States
------------------------------
Nic -

It worked! Fantastic!

Thank you for the VOC entry and for the additional information.

Joe Miele

------------------------------
Joseph Miele
Self Registered
Clinton IA United States
------------------------------