<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: ArcGIS Pro Toolbox throws an error when using subprocess. in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/arcgis-pro-toolbox-throws-an-error-when-using/m-p/1581665#M92657</link>
    <description>&lt;P&gt;Your python 2.7 process is inheriting the ArcGIS Pro environment.&amp;nbsp; Have a look at the &lt;A href="https://docs.python.org/3/library/subprocess.html" target="_self"&gt;Python 3 subprocess&lt;/A&gt;&amp;nbsp;docs for the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;env&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;=&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;FONT face="courier new,courier"&gt;None&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;parameter. If you then have a look at the &lt;FONT face="courier new,courier"&gt;os.environ&lt;/FONT&gt; dict from your Python 2.7 install, you should be able to put together a dict of environment variables that you can pass to &lt;FONT face="courier new,courier"&gt;subprocess.check_output&lt;/FONT&gt; in your ArcGIS Pro Toolbox script.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Out of interest... why are you still using Python 2.7?&amp;nbsp; ArcGIS 10x script that doesn't run in ArcGIS Pro?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Feb 2025 08:09:43 GMT</pubDate>
    <dc:creator>Luke_Pinner</dc:creator>
    <dc:date>2025-02-04T08:09:43Z</dc:date>
    <item>
      <title>ArcGIS Pro Toolbox throws an error when using subprocess.</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcgis-pro-toolbox-throws-an-error-when-using/m-p/1581388#M92624</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm using ArcGIS Pro 2.9.0. To make this as simple as possible, I have done the following.&lt;/P&gt;&lt;P&gt;Created a Toolbox and added a tool called 'Check' to it.&lt;/P&gt;&lt;P&gt;The execution tab of this Check tool, calls a python script. This script is written in Python 3.7.11.&lt;/P&gt;&lt;P&gt;The script then calls the following code.&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;try:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; import subprocess&lt;BR /&gt;&amp;nbsp; &amp;nbsp; si = subprocess.STARTUPINFO()&lt;BR /&gt;&amp;nbsp; &amp;nbsp; si.dwFlags |= subprocess.STARTF_USESHOWWINDOW&lt;BR /&gt;&amp;nbsp; &amp;nbsp; 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)&lt;/P&gt;&lt;P&gt;except: subprocess.CalledProcessError as e:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; arcpy.AddMessage("Error occurred" + str(e))&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;arcpy.AddMessage(str(e.output))&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;arcpy.AddMessage(str(e.returncode))&lt;/P&gt;&lt;P&gt;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'&lt;/P&gt;&lt;P&gt;However, when I run the Check tool from the ArcGIS Pro application, I get the following error.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error occurredCommand '['path to python','path to hello']' returned non-zero exit status 1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site.py", line 177 file=sys.stderr)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;^&lt;/P&gt;&lt;P&gt;SyntaxError: invalid syntax&lt;BR /&gt;1&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Feb 2025 17:22:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcgis-pro-toolbox-throws-an-error-when-using/m-p/1581388#M92624</guid>
      <dc:creator>AndrewNoronha</dc:creator>
      <dc:date>2025-02-03T17:22:12Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Pro Toolbox throws an error when using subprocess.</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcgis-pro-toolbox-throws-an-error-when-using/m-p/1581665#M92657</link>
      <description>&lt;P&gt;Your python 2.7 process is inheriting the ArcGIS Pro environment.&amp;nbsp; Have a look at the &lt;A href="https://docs.python.org/3/library/subprocess.html" target="_self"&gt;Python 3 subprocess&lt;/A&gt;&amp;nbsp;docs for the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;env&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;=&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;FONT face="courier new,courier"&gt;None&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;parameter. If you then have a look at the &lt;FONT face="courier new,courier"&gt;os.environ&lt;/FONT&gt; dict from your Python 2.7 install, you should be able to put together a dict of environment variables that you can pass to &lt;FONT face="courier new,courier"&gt;subprocess.check_output&lt;/FONT&gt; in your ArcGIS Pro Toolbox script.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Out of interest... why are you still using Python 2.7?&amp;nbsp; ArcGIS 10x script that doesn't run in ArcGIS Pro?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2025 08:09:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcgis-pro-toolbox-throws-an-error-when-using/m-p/1581665#M92657</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2025-02-04T08:09:43Z</dc:date>
    </item>
  </channel>
</rss>

