# Buggy code
def process(self, operation: Operation):
    filepath = self.get_valid_filepath(operation.filename)

    file_dir = os.path.dirname(filepath)
    file_name = os.path.basename(filepath)

    self.log.debug(f"Processing python script: {filepath}")

    argv = ["python3", filepath, "--PYTHONHOME", file_dir]
    envs = operation.env_vars_as_dict()
    t0 = time.time()
    try:
        run(argv, cwd=file_dir, env=envs, check=True)
    except Exception as ex:
        raise RuntimeError(f"Internal error executing {filepath}: {ex}") from ex

    t1 = time.time()
    duration = t1 - t0
    self.log.debug(f"Execution of {file_name} took {duration:.3f} secs.")


# Traceback (ModuleNotFoundError)
[I 10:35:22.335 LabApp] local 'request' - processing pipeline
Traceback (most recent call last):
File "/Users/patti/meetups/l_a_l_11_09/test_workspace/my-examples-repo/pipelines/hello_world/request.py", line 1, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
[E 10:35:22.403 LabApp] Uncaught exception POST /elyra/pipeline/schedule?1604687722331 (::1)
HTTPServerRequest(protocol='http', host='localhost:8888', method='POST', uri='/elyra/pipeline/schedule?1604687722331', version='HTTP/1.1', remote_ip='::1')
Traceback (most recent call last):
File "/Users/patti/anaconda3/envs/elyra_ga/lib/python3.7/site-packages/elyra/pipeline/processor_local.py", line 220, in process
run(argv, cwd=file_dir, env=envs, check=True)
File "/Users/patti/anaconda3/envs/elyra_ga/lib/python3.7/subprocess.py", line 512, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['python3', '/Users/patti/meetups/l_a_l_11_09/test_workspace/my-examples-repo/pipelines/hello_world/request.py', '--PYTHONHOME', '/Users/patti/meetups/l_a_l_11_09/test_workspace/my-examples-repo/pipelines/hello_world']' returned non-zero exit status 1.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/patti/anaconda3/envs/elyra_ga/lib/python3.7/site-packages/elyra/pipeline/processor_local.py", line 74, in process
operation_processor.process(operation)
File "/Users/patti/anaconda3/envs/elyra_ga/lib/python3.7/site-packages/elyra/pipeline/processor_local.py", line 222, in process
raise RuntimeError(f'Internal error executing {filepath}: {ex}') from ex
RuntimeError: Internal error executing /Users/patti/meetups/l_a_l_11_09/test_workspace/my-examples-repo/pipelines/hello_world/request.py: Command '['python3', '/Users/patti/meetups/l_a_l_11_09/test_workspace/my-examples-repo/pipelines/hello_world/request.py', '--PYTHONHOME', '/Users/patti/meetups/l_a_l_11_09/test_workspace/my-examples-repo/pipelines/hello_world']' returned non-zero exit status 1.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/patti/anaconda3/envs/elyra_ga/lib/python3.7/site-packages/tornado/web.py", line 1703, in _execute
result = await result
File "/Users/patti/anaconda3/envs/elyra_ga/lib/python3.7/site-packages/elyra/pipeline/handlers.py", line 89, in post
response = await PipelineProcessorManager.instance().process(pipeline)
File "/Users/patti/anaconda3/envs/elyra_ga/lib/python3.7/site-packages/elyra/pipeline/processor.py", line 70, in process
res = await asyncio.get_event_loop().run_in_executor(None, processor.process, pipeline)
File "/Users/patti/anaconda3/envs/elyra_ga/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/Users/patti/anaconda3/envs/elyra_ga/lib/python3.7/site-packages/elyra/pipeline/processor_local.py", line 79, in process
raise RuntimeError(f'Error processing operation {operation.name}.') from ex
RuntimeError: Error processing operation request.
[E 10:35:22.407 LabApp] {
"Host": "localhost:8888",
"Connection": "keep-alive",
"Content-Length": "1871",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36",
"X-Xsrftoken": "2|d32b6c13|a2d7c54da22962e3437ecfb28af5d2ec|1602537750",
"Authorization": "token d0664a26a6f3c6a2143fd6d62f67f1d720cfacd56bd84f5b",
"Content-Type": "text/plain;charset=UTF-8",
"Accept": "*/*",
"Origin": "http://localhost:8888",
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Dest": "empty",
"Referer": "http://localhost:8888/lab/workspaces/auto-v",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9,de;q=0.8",
"Cookie": "_xsrf=2|d32b6c13|a2d7c54da22962e3437ecfb28af5d2ec|1602537750; username-localhost-8889=\"2|1:0|10:1604624344|23:username-localhost-8889|44:ZWQ2OGI0ZGU3ZmU4NGZjNjg1OTQ4N2QzYzAwZTU3Njg=|8a9048391f96af4e758d57e781becdcd13b85f8be60b3b491314c46a1751ac16\"; username-localhost-8888=\"2|1:0|10:1604687721|23:username-localhost-8888|44:MmU1Nzg0M2JmZWNhNDI1NzhjYjRjNTBlN2UwNDE0ODI=|c819c59b00df1be5e939a9e642b1d056562cd6115a6f5d343faf505eaed1da6b\""
}
[E 10:35:22.407 LabApp] 500 POST /elyra/pipeline/schedule?1604687722331 (::1) 73.43ms referer=http://localhost:8888/lab/workspaces/auto-v

# Fixed code
def process(self, operation: Operation):
    filepath = self.get_valid_filepath(operation.filename)

    file_dir = os.path.dirname(filepath)
    file_name = os.path.basename(filepath)

    self.log.debug(f"Processing python script: {filepath}")

    argv = ["python3", filepath, "--PYTHONHOME", file_dir]

    envs = os.environ  # Make sure this process's env is "available" in subprocess
    envs.update(operation.env_vars_as_dict())
    t0 = time.time()
    try:
        run(argv, cwd=file_dir, env=envs, check=True)
    except Exception as ex:
        raise RuntimeError(f"Internal error executing {filepath}: {ex}") from ex

    t1 = time.time()
    duration = t1 - t0
    self.log.debug(f"Execution of {file_name} took {duration:.3f} secs.")