Python Running Commands on Commandline

Hi there, I am running into some issues with an extension that I have written for Omniverse where it calls a workflow that runs a simulation.

I can run an command like this in a python script (same file location as the extension etc etc) and it run the workflow perfectly:

output = subprocess.run(cmd, capture_output=True, text=True)

print(f'stdout:\n\n{output.stdout}\n\n')
print(f'stderr:\n\n{output.stderr}\n\n')

whereas when I run this command from inside the extension (say a button in omniverse that exectues a function that runs the same line of code) it throws an error:

	Traceback (most recent call last):
	  File "/usr/bin/cwltool", line 33, in <module>
	    sys.exit(load_entry_point('cwltool==3.1.20220224085855', 'console_scripts', 'cwltool')())
	  File "/usr/bin/cwltool", line 25, in importlib_load_entry_point
	    return next(matches).load()
	  File "/usr/lib/python3/dist-packages/importlib_metadata/__init__.py", line 168, in load
	    module = import_module(match.group('module'))
	  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
	    return _bootstrap._gcd_import(name[level:], package, level)
	  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
	  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
	  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
	  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
	  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
	  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
	  File "/usr/lib/python3/dist-packages/cwltool/main.py", line 47, in <module>
	    from . import CWL_CONTENT_TYPES, workflow
	  File "/usr/lib/python3/dist-packages/cwltool/workflow.py", line 22, in <module>
	    from . import command_line_tool, context, procgenerator
	  File "/usr/lib/python3/dist-packages/cwltool/command_line_tool.py", line 50, in <module>
	    from .docker import DockerCommandLineJob
	  File "/usr/lib/python3/dist-packages/cwltool/docker.py", line 22, in <module>
	    from .job import ContainerCommandLineJob
	  File "/usr/lib/python3/dist-packages/cwltool/job.py", line 36, in <module>
	    import psutil
	  File "/usr/lib/python3/dist-packages/psutil/__init__.py", line 102, in <module>
	    from . import _pslinux as _psplatform
	  File "/usr/lib/python3/dist-packages/psutil/_pslinux.py", line 26, in <module>
	    from . import _psutil_linux as cext
	ImportError: cannot import name '_psutil_linux' from 'psutil' (/usr/lib/python3/dist-packages/psutil/__init__.py)

Looking at it I wonder if it is something to do with the python environment that omniverse is using doesn’t match up with the environment I have things installed in on my machine? It used to work using both this method and using os.sys() but after installing a newer version of python it seems to have broken…

Anyone got any ideas?

Hi @william.smith-14. I do think that this is an environment issue. I think I’d expect the traceback to show paths to the Python embedded with Kit. Which Omniverse app are you using in this container? Did you create the container or is it one we provided?