Products Resources Support About Us

Help needed to call python function please


#1

Running into what I think is a Python path issue.

  1. Running UVPE 11.3.1
  2. Created my own account (dvh)
  3. Created a python program folder (c:\U2\dvh\pyprogs)
  4. Created a ‘dvh.pth’ file with the path to python program folder (above) and put it in the …\UV\python folder
  5. Created a python function just to test getting to the call. – pyfunctioncall_test.py …
  def test_call(i_list):
      print('In pyfunctioncall_test: i_list:' + i_list)
  1. Created and ran a BASIC ‘driver’ to call the python function

    module_name = ‘pyfunctioncall_test’

  function_name = 'test_call'
  pyresult = PyImport(module_name)
 IF @PYEXCEPTIONTYPE = "" THEN
      CRT "py call successfull"
  END ELSE
      CRT "EXCEPTION TYPE IS " :@PYEXCEPTIONTYPE
      CRT "EXCEPTION MESSAGE IS " :@PYEXCEPTIONMSG
      CRT "EXCEPTIONTRACEBACK IS " :@PYEXCEPTIONTRACEBACK
      stop
  END
  print "Enter param...":
  input x
  pyresult = PyCallFunction(module_name, function_name, x)
  IF @PYEXCEPTIONTYPE = "" THEN
      CRT "py call successfull"
  END ELSE
      CRT "EXCEPTION TYPE IS " :@PYEXCEPTIONTYPE
      CRT "EXCEPTION MESSAGE IS " :@PYEXCEPTIONMSG
      CRT "EXCEPTIONTRACEBACK IS " :@PYEXCEPTIONTRACEBACK
  END

Not getting past the ImportError when trying to import the module. Assuming that UV doesn’t look for and in turn expects a ‘.py’ extension for python modules (as indicated in the examples, but not the documentation).

Read as much documentation as I could. Still doesn’t work.

Help would be appreciated.


#2

After more work, I found that I don’t need to do the PyImport. So i eliminated that segment, but still cannot get UV Basic routine that calls the python module/function to work. Still getting import error.

I was able to get the routines to work if I put them in the XDEMO account. So I’m pretty sure that UV is NOT recognizing my custom .pth file in the …\UV\python folder.

Thanks,

Dave


#3

Interesting, I have used multiple .pth files, and have not had an issue. If you drop to the python prompt, and try the import does it work?

if it does not work, check to see what it has set for the path:
i.e.
python> import sys
python> sys.path
[‘C:\U2\ud82\Python\python34.zip’, ‘C:\U2\ud82\Python\DLLs’, ‘C:\U2\ud82\Python\lib’, ‘C:\U2\ud82\bin’, ‘C:\U2\ud82\Python’, ‘C:\U2\ud82\XDEMO\PP’, ‘C:\U2\ud82\Python\lib\site-packages’]
python>

Mike


#4

Mike, thanks so much for getting back. Sorry to report that the sys.path output does not include my own path in the dvh.pth file in the python uv folder. The dvh.pth has this line only: C:\U2\dvh\pymodules. Here is the UV console when do the sys.path thing…

C:\U2\dvh>uv

C:\U2\dvh>c:\u2\uv\bin\uv
UniVerse Command Language 11.3
Copyright Rocket Software, Inc. or its affiliates, All Rights Reserved 1985-2016
dvh logged on: Fri Feb 02 12:43:49 2018

WHO
2 dvh From MAEAGLE\daveh
PYTHON
python> import sys
python> sys.path
[‘C:\U2\UV\python\python34.zip’, ‘C:\Users\daveh\AppData\Local\Programs\Python\Python34\DLLs’, ‘C:\Users\daveh\AppData\Local\Programs\Python\Python34\lib’, ‘c:\u2\uv\bin’, ‘C:\Users\daveh\AppData\Local\Programs\Python\Python34’, ‘C:\U2\UV\XDEMO\PP’, ‘C:\Users\daveh\AppData\Local\Programs\Python\Python34\lib\site-packages’]
python>

I can run the modules with RUNPY, but they still don’t get called with the subroutine. Again, I am using the Personal Edition. I have restarted Universe Services many times.

Thanks for helping,

Dave


#5

Sorry to ask this: "can you check that the file name is dvh.pth and not dvh.pth.txt

If you are still having a problem open a support call, it most likely will get to me, and we can do a webex


#6

Michael,

No problem on the double check. Here is a screen shot of the …\UV\python directory, which has (as you can see) my .pth file without the ‘.txt’ suffix.

[/uploads/rocketsoftware/original/1X/40372569ebaf33059556401097dcd36e6eb1ef30.jpg]

Its only line is:
C:\U2\dvh\pymodules

And here is the contents of that folder:

[/uploads/rocketsoftware/original/1X/28835893e618bb5f73b701af3354a9af133c90cc.jpg]

As it’s been a while since I have created a support ticket with Rocket, can you please give me the URL. Will it be a problem since I’m using the Personal Edition?

Thanks a lot,

Dave


#7

First, sorry for not checking in earlier. Your pth file needs to go in the universe python folder…

.pth configuration files
For the u2py extension module to be loadable in Python, the u2.pth file is placed in specific directories under the bundled Python installation directory:
:black_small_square: On Windows for UniData, $UDTHOME\python
:black_small_square: On Windows for UniVerse, $UVHOME\python
:black_small_square: On Linux for UniData, $UDTHOME/python/python#.#/site-packages
:black_small_square: On Linux for UniVerse, $UVHOME/python/python#.#/site-packages

What is the contents of your $UVHOME?
This your pth file in python folder in that directory?

I don’t have UVPE running on Windows, I have it running on Linux, but my custom path seems to work.


#8

Hello Raul,

Indeed my ‘dvh.pth’ file is in the C:\U2\UV\python folder. My environment path setting for UVHOME is UVHOME=C:\U2\UV.

I have been in communication with Michael Rajkowski about this as well. A copy of our email exchange is attached.

I can try putting UVPE on a linux docker container to see if that works if you suggest I do that.

Also, is it preferable for me to respond by reply email or through a post reply on the forum???

Thanks,

Dave


#9

I am a fan of keeping the thread public as a way to contribute. I have researched where my .pth files end up… It is in the site-packages directory. Search for u2.pth and put your pth file in the same place.

[nmrad@nmsplunk site-packages]$ cat /.uvhome
/opt/rocket/uv
[nmrad@nmsplunk site-packages]$ pwd
/opt/rocket/uv/python/lib/python3.4/site-packages
[nmrad@nmsplunk site-packages]$ ls ./u2.pth
./u2.pth

Hope this helps.


#10

I just reviewed your picture again. I don’t know why the u2.pth is in python instead of site-pacakges. Try it in site-packages.


#11

What is the contents of your u2.pth file? Is that directory in your sys.path output?


#12

Raul,

The reason I had the u2.pth file in the python folder is because the documentation

For the u2py extension module to be loadable in Python, the u2.pth file is placed in specific
> directories under the bundled Python installation directory:
:black_small_square: On Windows for UniData, $UDTHOME\python
:black_small_square: On Windows for UniVerse, $UVHOME\python
:black_small_square: On Linux for UniData, $UDTHOME/python/python#.#/site-packages
:black_small_square: On Linux for UniVerse, $UVHOME/python/python#.#/site-packages
The full path of $UDTBIN or $UVBIN is listed in the u2.pth file so that Python will load it into its
search path when starting up. The XDEMO’s PP directory path is included in the u2.pth file. Do not
add any custom paths to the u2.pth file because this file is overwritten on upgrades.
To add your directories containing Python modules to the module search path, place a unique path
> configuration file with the .pth extension in the appropriate path for your database and platform,
> listed above. Each path needed is included on a separate line in the custom .pth files. For example,
on UniVerse and Windows in the $UVHOME/python directory with a file called myprograms.pth,
the paths will look like:
c:\U2\Accounts\SALES\PP
c:\U2\Accounts\RENTALS\PP

says it needs to be placed there. After initial install that’s where I found the u2.pth file.

But weirdness abounds, because now is seems to be working with those files in the python folder. It is also working with them in the site packages folder as well.

So, attributing this to my confusion and a bit of trial and error. It is working as expected now.

I should also like to let you know that I have also changed the Python version to point to and use one of my Python “virtualenv” virtual environments that have quite a bit of pip installed packages. Python in U2 imports them just fine.

Thanks to Michael and Raul for their help and patience.