Hi,
I'm using ArcGIS Pro 2.9.0. To make this as simple as possible, I have done the following.
Created a Toolbox and added a tool called 'Check' to it.
The execution tab of this Check tool, calls a python script. This script is written in Python 3.7.11.
The script then calls the following code.
import arcpy
try:
import subprocess
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
result = subprocess.check_output(['path to a location on my C drive which has python 2.7 32bit', 'path to a python file called hello.py', stderr=subprocess.STDOUT, shell=False, startupinfo=si, text=True)
except: subprocess.CalledProcessError as e:
arcpy.AddMessage("Error occurred" + str(e))
arcpy.AddMessage(str(e.output))
arcpy.AddMessage(str(e.returncode))
hello.py simply writes a hello.py to a folder. I've tested this in isolation and it writes the helloworld.txt file with the words 'hello world'
However, when I run the Check tool from the ArcGIS Pro application, I get the following error.
Error occurredCommand '['path to python','path to hello']' returned non-zero exit status 1.
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site.py", line 177 file=sys.stderr)
^
SyntaxError: invalid syntax
1
I'm looking for possible reasons for this error. Running hello.py from Python 3 gives no error. Running hello.py from Python 2.7 gives no error. Running the above code in Pycharm or in python directly gives no error. Its only when I run the tool in ArcGIS Pro, do I get the above error in the tool's output log on screen. And the file with 'Hello World' doesnt get created. Thanks in advance.