Using InvokeCode for python code


I am using Invoke code activity for execute python code but when I tried to import a module it returns the error message “# ModuleNotFoundError : No module named ‘langid’

The code inside OpenRPA.Script.Activities.InvokeCode

import langid as lang
print(lang.classify("Sprint 28"))

I made differents test:

  1. Create a file with extension .py with this code above and execute it through command prompt. It works well but outside OpenRPA.
  2. Locate the file in C:\Documents\OpenRPA, this option works partially well since it looks for other python related, which makes me think that, this is not the best way to do it.
  3. If I use any functionality from standard modules of python it works.
  4. I called the python file from Excel macro and it works well, but I don’t really like this option, it seems to me that it is very slow.
  5. I tried to modify the setting “Script_python_exe_path”: “C:/Python” but itseems to be no difference.

The problem seems to be when you are using a python module that is not part of the standard libraries., so my question is: how can I use other modules of python inside InvokeCode activity?

Thanks in advance!

OpenRPA uses python embedded, it allows for complete control over the python runtime, that is needed to map variables in/out of python. Therefor it cannot see packages you installed in your “own” python. So you need to use the pip install activity or run pip install from C:\Users%USERNAME%\AppData\Local\python-3.7.3-embed-amd64

The draw back is, the only python 3.7 is suppurted. If you have a supported version of python 3.7 in your PATH you can go to settings → recorder plugins → Scripting and tell it to not used the embedded version, but the one in path. The embedded version does not have th TK liberaries so any python liberares that rely in GUI will not work, using your locally installed will fix that but then you MUST use a supported version of python 3.7

If you need a “real” python envoriment, you will need to call python.exe your self using Start Process and then map any data you need in/out in some other way, like a local json file.
OR wait a few days to version 1.5 of openflow to be released, then you can run real python inside openflow

This also allows using the “opeiap” py liberary to be installed so you can talk directly to openflow from python.

Ok I understand, we will implement it that way until having the new version.

Thanks you very much!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.