Conrad Hess Posted March 20, 2019 Share Posted March 20, 2019 I have a Python script that uses libraries unavailable in IronPython. I would like to trigger the python script to run in a python environment external to spotfire. Typically from R I can fire off a script like this using the following code: input_fun_str = paste("Path_to_env\python Path_to_scripttest_function.py", arg1) system("cmd.exe", input=input_fun_str) This did not work for me in TERR unfortunatley. Is there a method to trigger a python script in an external environment from spotfire Thanks Link to comment Share on other sites More sharing options...
William Dunlap Posted March 21, 2019 Share Posted March 21, 2019 What version of TERR are you using. With TERR-4.5.0, on a Windows machine with Continuum/Anaconda's python installed, I get > cat("print(1+2/3)n", file=tf <- tempfile()) > result <- system(paste("C:\Users\wdunlap\AppData\Local\Continuum\anaconda3\pkgs\python-3.6.4-h0c2934d_2\python.exe", normalizePath(tf)), intern=TRUE) > result [1] "1.6666666666666665" Link to comment Share on other sites More sharing options...
Matthew Stahl Posted March 22, 2019 Share Posted March 22, 2019 It is possible to execute C Python from IronPython. Here's an example: from System.Diagnostics import Process from System.Diagnostics import ProcessStartInfo from System.Diagnostics import ProcessWindowStyle process = Process() startInfo = ProcessStartInfo() startInfo.WindowStyle = ProcessWindowStyle.Hidden startInfo.FileName = "C:\python\python.exe" startInfo.Arguments = "test_function.py" process.StartInfo = startInfo process.Start() Link to comment Share on other sites More sharing options...
Conrad Hess Posted March 22, 2019 Author Share Posted March 22, 2019 Thanks, this worked for me! Link to comment Share on other sites More sharing options...
Hung Huynh Posted July 24, 2019 Share Posted July 24, 2019 Do you have test_function.py in the same folder as the python exe Link to comment Share on other sites More sharing options...
Matthew Stahl Posted July 24, 2019 Share Posted July 24, 2019 The script doesn't have to be in the same folder as the python executable. The full path to the script may be provided in the arguments (i.e. startInfo.Arguments = "C:\full-path-to-test-function\test_function.py") Link to comment Share on other sites More sharing options...
Hung Huynh Posted July 24, 2019 Share Posted July 24, 2019 Okay so I specified the full path for my python script named hello.py I had a print statement(prints out "hi") in my py script just to make sure that it ran through however my Spotfire output console is blank. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now