I am trying to build on this example in:
https://www.slicer.org/wiki/Documentation/Nightly/Developers/Python_scripting#How_to_run_Python_script_using_a_non-Slicer_Python_environment
This
python_path = "C:/Users/amaga/AppData/Local/Continuum/anaconda3/python"
command_line = [python_path, "-c", "import pyRserve; conn = pyRserve.connect(); print(conn.eval('3 + 5'))"]
from subprocess import check_output
command_result = check_output(command_line, env=slicer.util.startupEnvironment())
print(command_result)
fails with error.
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Program Files\Slicer 4.11.0-2018-11-02\lib\Python\Lib\subprocess.py", line 219, in check_output
raise CalledProcessError(retcode, cmd, output=output)
CalledProcessError: Command ‘[‘C:/Users/amaga/AppData/Local/Continuum/anaconda3/python’, ‘-c’, "import pyRserve; conn = pyRserve.connect(); print(conn.eval(‘3 + 5’))"]’ returned non-zero exit status 120
But in the interactive python console import pyRserve; conn = pyRserve.connect(); print(conn.eval(‘3 + 5’))
returns the correct value. So I know Rserve is working.
What is the correct way of passing bunch of commands to the external python in this context?