Skip to main content

I posted something similar to this in this thread:

Rocket U2 | UniVerse & UniData

Rocketsoftware remove preview
Rocket U2 | UniVerse & UniData
Hi allI have some problems when connecting to servers using uopy, as the PATH variable is wrong.From the terminal console:>SH -c "echo $PATH"/usr/local/bin:/usr
View this on Rocketsoftware >

I have a variable defined in /etc/environment:

[hcortiguera@catalogo20 ~]$ cat /etc/environment
OPENAI_API_KEY=MY_API_KEY

I can read it from command-line Python:

[hcortiguera@catalogo20 ~]$ /u2/uv/python/bin/python3
Python 3.9.2 (default, Jun 15 2021, 01:30:50)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ['OPENAI_API_KEY']
'MY_API_KEY'

But I can't read it when I call Python from BASIC


NOMBRE.VAR.ENTORNO='OPENAI_API_KEY'

NOMBRE.SCRIPT='consultaVariableEntorno'
NOMBRE.FUNCION='get_var_entorno'

RESPUESTA=PyCallFunction(NOMBRE.SCRIPT,NOMBRE.FUNCION,NOMBRE.VAR.ENTORNO)
CRT '[EJECUTADO]'
CRT '[':RESPUESTA:']'

The Python code:

import os

def get_var_entorno(var_entorno):
    return str(os.environ.get(var_entorno, '?'))

The output from BASIC:

[EJECUTADO]
[?]

Why the Python interpreter is not reading /etc/environment?



------------------------------
Héctor Cortiguera
Quiter Servicios Informaticos SL
------------------------------

I posted something similar to this in this thread:

Rocket U2 | UniVerse & UniData

Rocketsoftware remove preview
Rocket U2 | UniVerse & UniData
Hi allI have some problems when connecting to servers using uopy, as the PATH variable is wrong.From the terminal console:>SH -c "echo $PATH"/usr/local/bin:/usr
View this on Rocketsoftware >

I have a variable defined in /etc/environment:

[hcortiguera@catalogo20 ~]$ cat /etc/environment
OPENAI_API_KEY=MY_API_KEY

I can read it from command-line Python:

[hcortiguera@catalogo20 ~]$ /u2/uv/python/bin/python3
Python 3.9.2 (default, Jun 15 2021, 01:30:50)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ['OPENAI_API_KEY']
'MY_API_KEY'

But I can't read it when I call Python from BASIC


NOMBRE.VAR.ENTORNO='OPENAI_API_KEY'

NOMBRE.SCRIPT='consultaVariableEntorno'
NOMBRE.FUNCION='get_var_entorno'

RESPUESTA=PyCallFunction(NOMBRE.SCRIPT,NOMBRE.FUNCION,NOMBRE.VAR.ENTORNO)
CRT '[EJECUTADO]'
CRT '[':RESPUESTA:']'

The Python code:

import os

def get_var_entorno(var_entorno):
    return str(os.environ.get(var_entorno, '?'))

The output from BASIC:

[EJECUTADO]
[?]

Why the Python interpreter is not reading /etc/environment?



------------------------------
Héctor Cortiguera
Quiter Servicios Informaticos SL
------------------------------

Normally that would be referenced with your login shell, so the environment variables pass through to the script when you call it from the command line.  My guess is that your BASIC program might be invoked at boot time or via automated process, so the environment is empty.  You'd have to ensure that the environment is referenced by the startup script for your BASIC program, so the environment variables remain persistent OR you can explicitly reference that file in your Python script.



------------------------------
Tilghman Lesher
Senior Developer
Self Registered
WHITES CREEK TN US
------------------------------

I posted something similar to this in this thread:

Rocket U2 | UniVerse & UniData

Rocketsoftware remove preview
Rocket U2 | UniVerse & UniData
Hi allI have some problems when connecting to servers using uopy, as the PATH variable is wrong.From the terminal console:>SH -c "echo $PATH"/usr/local/bin:/usr
View this on Rocketsoftware >

I have a variable defined in /etc/environment:

[hcortiguera@catalogo20 ~]$ cat /etc/environment
OPENAI_API_KEY=MY_API_KEY

I can read it from command-line Python:

[hcortiguera@catalogo20 ~]$ /u2/uv/python/bin/python3
Python 3.9.2 (default, Jun 15 2021, 01:30:50)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ['OPENAI_API_KEY']
'MY_API_KEY'

But I can't read it when I call Python from BASIC


NOMBRE.VAR.ENTORNO='OPENAI_API_KEY'

NOMBRE.SCRIPT='consultaVariableEntorno'
NOMBRE.FUNCION='get_var_entorno'

RESPUESTA=PyCallFunction(NOMBRE.SCRIPT,NOMBRE.FUNCION,NOMBRE.VAR.ENTORNO)
CRT '[EJECUTADO]'
CRT '[':RESPUESTA:']'

The Python code:

import os

def get_var_entorno(var_entorno):
    return str(os.environ.get(var_entorno, '?'))

The output from BASIC:

[EJECUTADO]
[?]

Why the Python interpreter is not reading /etc/environment?



------------------------------
Héctor Cortiguera
Quiter Servicios Informaticos SL
------------------------------

Héctor,

I assume you are trying to set up a virtual python environment.  I have not tried that myself, but believe the issue is the difference between the Client connection you are making with uopy and the python used on the server.

uopy is client based, while u2py is the server side module used to interact with UniData/UniVerse,  once you start a U2 connection, any calls to Python will use the Version of Python set up for the U2 server.  This information is in .pyconfig file.

IE:  for my laptop on UniData on Windows it is at C:\\U2\\ud83\\.pyconfig

and contains:

PYHOME=C:\\U2\\ud83\\Python
PYLIB=C:\\U2\\ud83\\Python\\python311.dll

---

Note that if you connect to U2 with uopy, and then have a Basic program call Python, it will be the server side python that will be used, and not the client side python, which could be on a different server.



------------------------------
Mike Rajkowski
MultiValue Product Evangelist
Rocket Internal - All Brands
US
------------------------------

Héctor,

I assume you are trying to set up a virtual python environment.  I have not tried that myself, but believe the issue is the difference between the Client connection you are making with uopy and the python used on the server.

uopy is client based, while u2py is the server side module used to interact with UniData/UniVerse,  once you start a U2 connection, any calls to Python will use the Version of Python set up for the U2 server.  This information is in .pyconfig file.

IE:  for my laptop on UniData on Windows it is at C:\\U2\\ud83\\.pyconfig

and contains:

PYHOME=C:\\U2\\ud83\\Python
PYLIB=C:\\U2\\ud83\\Python\\python311.dll

---

Note that if you connect to U2 with uopy, and then have a Basic program call Python, it will be the server side python that will be used, and not the client side python, which could be on a different server.



------------------------------
Mike Rajkowski
MultiValue Product Evangelist
Rocket Internal - All Brands
US
------------------------------

Hi Mike

No venvs here, I'm just calling Python from BASIC via PyCallFunction. Neither I'm using uopy.

I'll try the .pyconfig file.



------------------------------
Héctor Cortiguera
Quiter Servicios Informaticos SL
------------------------------

Héctor,

I assume you are trying to set up a virtual python environment.  I have not tried that myself, but believe the issue is the difference between the Client connection you are making with uopy and the python used on the server.

uopy is client based, while u2py is the server side module used to interact with UniData/UniVerse,  once you start a U2 connection, any calls to Python will use the Version of Python set up for the U2 server.  This information is in .pyconfig file.

IE:  for my laptop on UniData on Windows it is at C:\\U2\\ud83\\.pyconfig

and contains:

PYHOME=C:\\U2\\ud83\\Python
PYLIB=C:\\U2\\ud83\\Python\\python311.dll

---

Note that if you connect to U2 with uopy, and then have a Basic program call Python, it will be the server side python that will be used, and not the client side python, which could be on a different server.



------------------------------
Mike Rajkowski
MultiValue Product Evangelist
Rocket Internal - All Brands
US
------------------------------

Hi Mike

I tried putting some variables into .pyconfig, but then the execution fails.

cat /usr/uv/.pyconfig
PYHOME=/usr/uv/python
PYLIB=/usr/uv/python/lib/libpython3.11.so
PYTHONUSERBASE=/usr/lib/python3.11/

BASIC code

*TEST_HECTOR

NOMBRE.VAR.ENTORNO='OPENAI_API_KEY'

NOMBRE.SCRIPT='test_import'
NOMBRE.FUNCION='test_env'

RESPUESTA=PyCallFunction(NOMBRE.SCRIPT,NOMBRE.FUNCION,'')
CRT '[EJECUTADO]'
CRT '[':RESPUESTA:']'

>RUN UP TEST_HECTOR
Invalid config parameter, PYTHONUSERBASE=/usr/lib/python3.11/



------------------------------
Héctor Cortiguera
Quiter Servicios Informaticos SL
------------------------------

Hi Mike

I tried putting some variables into .pyconfig, but then the execution fails.

cat /usr/uv/.pyconfig
PYHOME=/usr/uv/python
PYLIB=/usr/uv/python/lib/libpython3.11.so
PYTHONUSERBASE=/usr/lib/python3.11/

BASIC code

*TEST_HECTOR

NOMBRE.VAR.ENTORNO='OPENAI_API_KEY'

NOMBRE.SCRIPT='test_import'
NOMBRE.FUNCION='test_env'

RESPUESTA=PyCallFunction(NOMBRE.SCRIPT,NOMBRE.FUNCION,'')
CRT '[EJECUTADO]'
CRT '[':RESPUESTA:']'

>RUN UP TEST_HECTOR
Invalid config parameter, PYTHONUSERBASE=/usr/lib/python3.11/



------------------------------
Héctor Cortiguera
Quiter Servicios Informaticos SL
------------------------------

Héctor,

I am a bit confused.  The last post is showing 3.11, but your initial errors are showing 3.9.2.  It looks like you may have an issue with the PATH variables, environment variables when you started python from the command line, or a symbolic link issue with python3.

.pyconfig is used were we set the path to the active version of Python.  It is used when starting/entering python from a U2 process.  By default it points to the python shipped with U2.  If the version you are on was shipped with 3.11, you can not point it at a 3.9 version.  ( it is possible to switch to another 3.11.x version if you want/need, but I do not think that will help with your issue.

I am wondering what you are trying to attempt.  Are you trying to set up a virtual python environment or are you just trying set python to find the modules you imported?



------------------------------
Mike Rajkowski
MultiValue Product Evangelist
Rocket Internal - All Brands
US
------------------------------