<?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: Execute Python 2 Code via Python 3 in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431719#M33940</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I tried it with a newly-created, simple MXD containing a feature class from a FGDB and a basemap.&amp;nbsp; I also tried this on another computer, both having the same version of ArcGIS Pro 2.4; one computer had ArcGIS Desktop 10.6.1 and the other had 10.7.1.&amp;nbsp; Same result on both machines.&amp;nbsp; I'm so confused.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 30 Dec 2019 18:36:38 GMT</pubDate>
    <dc:creator>WilliamCraft</dc:creator>
    <dc:date>2019-12-30T18:36:38Z</dc:date>
    <item>
      <title>Execute Python 2 Code via Python 3</title>
      <link>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431703#M33924</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to wrap some Python 2 code into Python 3 but having trouble getting the process to work correctly.&amp;nbsp; From ArcGIS Pro, I'm running a custom GP tool with the following code as its script.&amp;nbsp; My goal is to run my Python 2 code (stored in a separate script) against a series of MXDs in order to list the data source for each layer or table.&amp;nbsp; In my case, doing it this way yields no results.&amp;nbsp; The code runs in about 2 seconds and then terminates.&amp;nbsp; Any ideas?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PYTHON 3 SCRIPT (WRAPPER)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12px; font-family: 'courier new', courier, monospace;"&gt;import subprocess, os, winreg, sys, arcpy&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12px; font-family: 'courier new', courier, monospace;"&gt;try:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: 'courier new', courier, monospace;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;arcpy.AddMessage("Finding Python 2.7 installation directory...")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: 'courier new', courier, monospace;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;hKey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, &amp;nbsp;&amp;nbsp;&amp;nbsp;"SOFTWARE\\WOW6432Node\\Python\\PythonCore\\2.7\\InstallPath")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: 'courier new', courier, monospace;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;result = winreg.QueryValueEx(hKey, "")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: 'courier new', courier, monospace;"&gt;except:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: 'courier new', courier, monospace;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;arcpy.AddWarning("Python 2.7 installation directory was not found.")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: 'courier new', courier, monospace;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;arcpy.AddError("Script failed.")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: 'courier new', courier, monospace;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;sys.exit()&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12px; font-family: 'courier new', courier, monospace;"&gt;if os.path.exists(result + "\\python.exe"):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: 'courier new', courier, monospace;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;arcpy.AddMessage("Launching Python 2.7 executable...")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: 'courier new', courier, monospace;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;CREATE_NO_WINDOW = 0x8000000&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: 'courier new', courier, monospace;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;process = subprocess.Popen([result + "\\python.exe", "C:\\temp\\python\\ListMXDDataSources.py"], &amp;nbsp;&amp;nbsp;&amp;nbsp;stdout=subprocess.PIPE, stderr=subprocess.PIPE, creationflags = CREATE_NO_WINDOW, shell=True, stdin=None)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: 'courier new', courier, monospace;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;stdout, stderr = process.communicate()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: 'courier new', courier, monospace;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;arcpy.AddMessage('{}'.format(stdout.decode("utf-8")))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px; font-family: 'courier new', courier, monospace;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;arcpy.AddWarning('{}'.format(stderr.decode("utf-8")))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif;"&gt;&lt;STRONG&gt;PYTHON&amp;nbsp;2 SCRIPT&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 12px;"&gt;import arcpy, glob&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 12px;"&gt;rootDirectory = 'C:/temp'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 12px;"&gt;fileExtension = '.mxd'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 12px;"&gt;def main():&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 12px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;for f in glob.glob(rootDirectory + '/*' + fileExtension):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 12px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mxd = arcpy.mapping.MapDocument(f)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 12px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for df in arcpy.mapping.ListDataFrames(mxd, ''):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 12px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for lyr in arcpy.mapping.ListLayers(mxd, '', df):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 12px;"&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;if not lyr.isGroupLayer:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 12px;"&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;if lyr.isRasterLayer:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 12px;"&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;print "Raster Layer, {}".format(lyr)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 12px;"&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;elif lyr.isFeatureLayer:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 12px;"&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;print "Feature Layer, {}, {}".format(lyr, lyr.serviceProperties)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 12px;"&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;else:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 12px;"&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;print "Layer, {}".format(lyr)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 12px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for tbl in arcpy.mapping.ListTableViews(mxd, '', df):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 12px;"&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;print "Table, {}".format(tbl.dataSource)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 12px;"&gt;if __name__ == '__main__':&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 12px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;main()&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Dec 2019 19:58:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431703#M33924</guid>
      <dc:creator>WilliamCraft</dc:creator>
      <dc:date>2019-12-26T19:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Python 2 Code via Python 3</title>
      <link>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431704#M33925</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've taken the liberty of copying and pasting your code sample into the syntax highlighter; you'll get more responses in this format.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry , don't have any suggestions for you...&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; subprocess&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; os&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; winreg&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; sys&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; arcpy

 

&lt;SPAN class="keyword token"&gt;try&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
   arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Finding Python 2.7 installation directory..."&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
   hKey &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; winreg&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;OpenKey&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;winreg&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;HKEY_LOCAL_MACHINE&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;    &lt;SPAN class="string token"&gt;"SOFTWARE\\WOW6432Node\\Python\\PythonCore\\2.7\\InstallPath"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
   result &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; winreg&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;QueryValueEx&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;hKey&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;except&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
   arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddWarning&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Python 2.7 installation directory was not found."&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
   arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddError&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Script failed."&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
   sys&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;exit&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

 

&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; os&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;exists&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;result &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"\\python.exe"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
   arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Launching Python 2.7 executable..."&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
   CREATE_NO_WINDOW &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0x8000000&lt;/SPAN&gt;
   process &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; subprocess&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Popen&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;result &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"\\python.exe"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"C:\\temp\\python\\ListMXDDataSources.py"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;    stdout&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;subprocess&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;PIPE&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; stderr&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;subprocess&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;PIPE&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; creationflags &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; CREATE_NO_WINDOW&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; shell&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; stdin&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;None&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
   stdout&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; stderr &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; process&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;communicate&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
   arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'{}'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;stdout&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;decode&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"utf-8"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
   arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddWarning&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'{}'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;stderr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;decode&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"utf-8"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:24:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431704#M33925</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-12-11T19:24:28Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Python 2 Code via Python 3</title>
      <link>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431705#M33926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Joe.&amp;nbsp; The syntax highlighter isn't working properly for me so I was unable to do this myself.&amp;nbsp; Also FYI, I've just now made some revisions to my code as well.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Dec 2019 15:03:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431705#M33926</guid>
      <dc:creator>WilliamCraft</dc:creator>
      <dc:date>2019-12-27T15:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Python 2 Code via Python 3</title>
      <link>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431706#M33927</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey &lt;A href="https://community.esri.com/migrated-users/18382" target="_blank"&gt;William Craft&lt;/A&gt;! Have you tried running the python 2 portions of the script in ArcMap's python window or in IDLE that comes with the Python2.7 install with Desktop? That could help you determine if it is a problem with python 3 or python 2.7. The other thing you could do is add&amp;nbsp;a simplistic logging&amp;nbsp;system within the script to record where things are failing. This always helps me narrow down if it is my code or the setup I'm running the script in.&amp;nbsp;Below&amp;nbsp;is my favorite logging system to add to scripts which I've added to yours as an example. Note: You could instead of using the script file location in the create_log function hard code a path in the location variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; subprocess&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; os&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; winreg&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; arcpy
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; os&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; sys
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; time &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; localtime&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; strftime

&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;create_log&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;name&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; headers&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;None&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; ftype&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;".txt"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; subfolder&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;None&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    location &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; sys&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; subfolder &lt;SPAN class="keyword token"&gt;is&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;not&lt;/SPAN&gt; None&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        location &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; os&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;join&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;sys&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; subfolder&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    time_setup &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; strftime&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"%m_%d_%Y"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; localtime&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    logfile &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; os&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;join&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;location&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; name &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"_"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; time_setup &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; ftype&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;not&lt;/SPAN&gt; os&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;exists&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;logfile&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        f &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; open&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;logfile&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'wb'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
        &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; headers &lt;SPAN class="keyword token"&gt;is&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;not&lt;/SPAN&gt; None&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
            f&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;write&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;headers&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
            f&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;write&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"\n"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
        f&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;close&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; logfile


&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;Log&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;logfile&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; message&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    f &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; open&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;logfile&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'ab'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    f&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;write&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;message&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    f&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;write&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"\n"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    f&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;close&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;main&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    logfile &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; create_log&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Monitor"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; subfolder&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Monitor_Logs"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    Log&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;logfile&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"{} Created Log.\n"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;strftime&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"%m_%d_%Y_%H:%M:%S"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; localtime&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

    &lt;SPAN class="keyword token"&gt;try&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Finding Python 2.7 installation directory..."&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
        Log&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;logfile&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Finding python 2.7 installation directory"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
        hKey &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; winreg&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;OpenKey&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;winreg&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;HKEY_LOCAL_MACHINE&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;  &lt;SPAN class="string token"&gt;"SOFTWARE\\WOW6432Node\\Python\\PythonCore\\2.7\\InstallPath"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
        result &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; winreg&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;QueryValueEx&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;hKey&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;""&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;except&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddWarning&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Python 2.7 installation directory was not found."&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
        Log&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;logfile&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Python 2.7 installation directory was not found."&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
        arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddError&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Script failed."&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
        sys&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;exit&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

    &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; os&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;exists&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;result &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"\\python.exe"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
        arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Launching Python 2.7 executable..."&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
        Log&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;logfile&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Launching Python 2.7 executable..."&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
        CREATE_NO_WINDOW &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;0x8000000&lt;/SPAN&gt;
        process &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; subprocess&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Popen&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;result &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"\\python.exe"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"C:\\temp\\python\\ListMXDDataSources.py"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;    stdout&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;subprocess&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;PIPE&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; stderr&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;subprocess&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;PIPE&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; creationflags &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; CREATE_NO_WINDOW&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; shell&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; stdin&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;None&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
        stdout&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; stderr &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; process&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;communicate&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
        arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddMessage&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'{}'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;stdout&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;decode&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"utf-8"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
        Log&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;logfile&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'{}'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;stdout&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;decode&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"utf-8"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
        arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;AddWarning&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'{}'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;stderr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;decode&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"utf-8"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; __name__ &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'__main__'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    main&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:24:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431706#M33927</guid>
      <dc:creator>StephanieWendel</dc:creator>
      <dc:date>2021-12-11T19:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Python 2 Code via Python 3</title>
      <link>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431707#M33928</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you &lt;A href="https://community.esri.com/migrated-users/2575"&gt;Stephanie Wendel&lt;/A&gt;&amp;nbsp;for your help.&amp;nbsp;&amp;nbsp; The failure seems to be associated with the&amp;nbsp;&lt;EM&gt;site.py&lt;/EM&gt; file of Python 3.&amp;nbsp; The Python 2 script works perfectly fine on its own.&amp;nbsp; Here is the underlying error after printing the stderr output from the subprocess.Popen line in the Python 3 code (line 45&amp;nbsp;above):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="476949" alt="" class="jive-emoji image-1 jive-image j-img-original" src="/legacyfs/online/476949_2019-12-27 19_05_45-mRemoteNG - confCons.xml - VWRCRSSP (Desktop).png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 28 Dec 2019 01:06:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431707#M33928</guid>
      <dc:creator>WilliamCraft</dc:creator>
      <dc:date>2019-12-28T01:06:00Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Python 2 Code via Python 3</title>
      <link>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431708#M33929</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The screenshot is helpful.&amp;nbsp; The answer to your question/issue is that an ArcGIS Pro Python module is being called with a Python 2.7 interpreter.&amp;nbsp; In line 177 of site.py, the code uses a syntax for print that is only valid in Python 3 and not Python 2, hence the invalid syntax error.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 28 Dec 2019 22:58:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431708#M33929</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-12-28T22:58:54Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Python 2 Code via Python 3</title>
      <link>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431709#M33930</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; __future__ &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; print_function
&lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"hello"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;  &lt;SPAN class="comment token"&gt;# not   .... print "hello"&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;if you want to fix up the 2.7 script&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:24:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431709#M33930</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T19:24:34Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Python 2 Code via Python 3</title>
      <link>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431710#M33931</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dan, I don't think this will make any difference. Note that in 2.7 print() works just fine without the from __future__ import... I always use it now in my ArcMap code so my scripts will run in both - of course&amp;nbsp;the OPs&amp;nbsp;script can't run in both because is uses ArcMap arcpy methods.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;William, it looks to me from your error message that the PATH environment is causing the Pro site.py to get executed when Python 2.7 starts up.&amp;nbsp; The way to fix this is to make sure the shell you start with &lt;A href="https://docs.python.org/3/library/subprocess.html#subprocess.Popen"&gt;Popen&lt;/A&gt; has a PATH environment that doesn't include the Pro folders. This is done using the env parameter to Popen.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 29 Dec 2019 01:45:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431710#M33931</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2019-12-29T01:45:54Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Python 2 Code via Python 3</title>
      <link>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431711#M33932</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you everyone for your help.&amp;nbsp; Curtis, the suggestion you made seemed to get me past the error I was experiencing.&amp;nbsp; I set the PATH, PYTHONHOME, and PYTHONPATH variables to only reference the Python 2.7 folder (C:\Python27\ArcGIS10.6).&amp;nbsp; However, I'm now getting a new error when the 2.7 code executes.&amp;nbsp; Note that that 'result' variable is equivalent to the value of "&lt;SPAN&gt;C:\Python27\ArcGIS10.6".&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12px; font-family: 'courier new', courier, monospace;"&gt;process = subprocess.Popen(result + "\\python.exe C:\\temp\\python\\ListMXDDataSources.py", stdout=subprocess.PIPE, stderr=subprocess.PIPE, creationflags = CREATE_NO_WINDOW, shell=True, env={'PATH': result, 'PYTHONHOME': result, 'PYTHONPATH': result})&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12px; font-family: 'courier new', courier, monospace;"&gt;&lt;IMG alt="" class="jive-emoji image-1 jive-image j-img-original" src="/legacyfs/online/477168_2019-12-30 09_14_27-mRemoteNG - confCons.xml - VWRCRSSP (Desktop).png" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Dec 2019 15:15:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431711#M33932</guid>
      <dc:creator>WilliamCraft</dc:creator>
      <dc:date>2019-12-30T15:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Python 2 Code via Python 3</title>
      <link>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431712#M33933</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okay, i don't typically partake in troubleshooting discussions&amp;nbsp;this deep below the surface (and yet so way above my head). But this&amp;nbsp;thread is producing some "keeper" bits of information.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Looks like your code fails at the use of seed() at _hexlify(). Never heard of it but when you compare&amp;nbsp;random.py in 2.7 and 3.6 (my machine), you notice that&amp;nbsp;hexlify&amp;nbsp;shows up in 2.7...&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; __future__ &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; division
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; warnings &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; warn &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _warn
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; types &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; MethodType &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _MethodType&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; BuiltinMethodType &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _BuiltinMethodType
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; math &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; log &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _log&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; exp &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _exp&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; pi &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _pi&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; e &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _e&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; ceil &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _ceil
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; math &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; sqrt &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _sqrt&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; acos &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _acos&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; cos &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _cos&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; sin &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _sin
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; os &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; urandom &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _urandom
&lt;SPAN class="comment token"&gt;# =======================================&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; binascii &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; hexlify &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _hexlify
&lt;SPAN class="comment token"&gt;# =======================================&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; hashlib &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _hashlib‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but not in 3.6&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; warnings &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; warn &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _warn
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; types &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; MethodType &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _MethodType&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; BuiltinMethodType &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _BuiltinMethodType
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; math &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; log &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _log&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; exp &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _exp&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; pi &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _pi&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; e &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _e&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; ceil &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _ceil
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; math &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; sqrt &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _sqrt&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; acos &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _acos&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; cos &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _cos&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; sin &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _sin
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; os &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; urandom &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _urandom
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; _collections_abc &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; Set &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _Set&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; Sequence &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _Sequence
&lt;SPAN class="keyword token"&gt;from&lt;/SPAN&gt; hashlib &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; sha512 &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _sha512
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; itertools &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _itertools
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; bisect &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; _bisect
&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So maybe you still&amp;nbsp;have 2.x code searching for something in 3.x environment?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:24:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431712#M33933</guid>
      <dc:creator>Arne_Gelfert</dc:creator>
      <dc:date>2021-12-11T19:24:37Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Python 2 Code via Python 3</title>
      <link>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431713#M33934</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think I figured out how to get past this issue too, thanks to your comment, the information from Curtis and Joshua, and some online investigation into the error code from the screenshot above.&amp;nbsp; I added the following &lt;STRONG&gt;bold text&amp;nbsp;&lt;/STRONG&gt;to the environment parameter of my popen line:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12px; font-family: 'courier new', courier, monospace;"&gt;process = subprocess.Popen(result + "\\python.exe C:\\temp\\python\\ListMXDDataSources.py", stdout=subprocess.PIPE, stderr=subprocess.PIPE, creationflags = CREATE_NO_WINDOW, shell=True, env={'PATH': result, &lt;SPAN style="font-family: 'arial black', sans-serif;"&gt;&lt;STRONG&gt;'SYSTEMROOT': 'C:\windows'&lt;/STRONG&gt;&lt;/SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif; font-size: 15px;"&gt;Below is where things currently stand when I run my code as of now.&amp;nbsp; I think I'm getting much closer now.&amp;nbsp; Thank you to everyone.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif; font-size: 15px;"&gt;&lt;IMG alt="" class="jive-emoji image-1 jive-image j-img-original" src="/legacyfs/online/477169_2019-12-30 10_29_15-mRemoteNG - confCons.xml - VWRCRSSP (Desktop).png" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Dec 2019 16:30:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431713#M33934</guid>
      <dc:creator>WilliamCraft</dc:creator>
      <dc:date>2019-12-30T16:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Python 2 Code via Python 3</title>
      <link>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431714#M33935</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/18382" target="_blank"&gt;William Craft&lt;/A&gt;‌, how exactly are you executing your Python 3 script?&amp;nbsp; I just took the original code you posted when you first opened this thread and it runs fine for me with some test MXDs:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;arcgispro&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;py3&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; C&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;py3&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt;python D&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;\tmp\ListWrapper&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;py
Finding Python &lt;SPAN class="number token"&gt;2.7&lt;/SPAN&gt; installation directory&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;
Launching Python &lt;SPAN class="number token"&gt;2.7&lt;/SPAN&gt; executable&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;
Layer&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; wwf_terr_biome_type_smooth

WARNING&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;

&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;arcgispro&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;py3&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; C&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;py3&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:24:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431714#M33935</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-11T19:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Python 2 Code via Python 3</title>
      <link>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431715#M33936</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm running&amp;nbsp;it from ArcGIS Pro's catalog view via a custom toolbox/toolset.&amp;nbsp; There seems to be an issue with referencing the map document file&amp;nbsp;when creating the MXD object.&amp;nbsp; Are you running the code within the Python window in ArcGIS Pro?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="477189" alt="" class="jive-emoji image-1 jive-image j-img-original" src="/legacyfs/online/477189_2019-12-30 11_47_16-mRemoteNG - confCons.xml - VWRCRSSP (Desktop).png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Dec 2019 17:48:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431715#M33936</guid>
      <dc:creator>WilliamCraft</dc:creator>
      <dc:date>2019-12-30T17:48:54Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Python 2 Code via Python 3</title>
      <link>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431716#M33937</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I ran the code from the "Python Command Prompt" shortcut that is created when Pro is installed.&amp;nbsp; That shortcut just takes care of activating the correct/default Pro Python environment.&amp;nbsp; If you run your code from that command prompt, does it generate an error?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Dec 2019 17:52:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431716#M33937</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-12-30T17:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Python 2 Code via Python 3</title>
      <link>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431717#M33938</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Doing it the way you suggested still yields the same error for me: "RuntimeError: Object: CreateObject cannot open map document".&amp;nbsp; Looks like maybe our environments are different enough where it'll run for you but not me.&amp;nbsp; I am curious why my environment prevents the MXD object from being created.&amp;nbsp; Thanks for looking into this a bit more.&amp;nbsp; Much appreciated.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Dec 2019 17:57:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431717#M33938</guid>
      <dc:creator>WilliamCraft</dc:creator>
      <dc:date>2019-12-30T17:57:29Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Python 2 Code via Python 3</title>
      <link>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431718#M33939</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The RuntimeError you are now experiencing might be caused by a problematic MXD, not a Python 2/3 environment issue.&amp;nbsp; Are you getting the RuntimeError with any/all MXDs?&amp;nbsp; Can you try just a single MXD in a directory.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Dec 2019 18:09:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431718#M33939</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-12-30T18:09:56Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Python 2 Code via Python 3</title>
      <link>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431719#M33940</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I tried it with a newly-created, simple MXD containing a feature class from a FGDB and a basemap.&amp;nbsp; I also tried this on another computer, both having the same version of ArcGIS Pro 2.4; one computer had ArcGIS Desktop 10.6.1 and the other had 10.7.1.&amp;nbsp; Same result on both machines.&amp;nbsp; I'm so confused.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Dec 2019 18:36:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431719#M33940</guid>
      <dc:creator>WilliamCraft</dc:creator>
      <dc:date>2019-12-30T18:36:38Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Python 2 Code via Python 3</title>
      <link>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431720#M33941</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In the Python 2 script, I added an&amp;nbsp;&lt;STRONG&gt;os.startfile(f)&lt;/STRONG&gt; line of code to launch the 10.6 MXD interactively just to see what issues may arise.&amp;nbsp; The following errors are found when taking this approach:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="477190" alt="" class="jive-emoji image-1 jive-image j-img-original" src="/legacyfs/online/477190_2019-12-30 15_35_35-mRemoteNG - confCons.xml - VWRCRSSP (Desktop).png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="477215" alt="" class="jive-emoji jive-image image-2 j-img-original" src="/legacyfs/online/477215_2019-12-30 15_35_42-mRemoteNG - confCons.xml - VWRCRSSP (Desktop).png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried deleting my Normal.mxt but that only eliminates the first error shown above.&amp;nbsp; I can open this map document just fine by double clicking on it from Windows Explorer.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Dec 2019 21:36:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431720#M33941</guid>
      <dc:creator>WilliamCraft</dc:creator>
      <dc:date>2019-12-30T21:36:57Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Python 2 Code via Python 3</title>
      <link>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431721#M33942</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You have already set the PATH in env so this may not be your issue, but I have gotten a python2 call from python3 to work by doing a os.environ.copy() first before updating the path.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;replica_sync_command &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; f&lt;SPAN class="string token"&gt;"C:\\Python27\\ArcGIS10.4\\python.exe c:\\syncReplica_python2.py"&lt;/SPAN&gt;
python2_env &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; os&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;environ&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;copy&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
python2_env&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;update&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"PATH"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"C:\\Python27\\ArcGIS10.4"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
run_sync &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; subprocess&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;run&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;replica_sync_command&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;split&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; env&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;python2_env&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; stdout&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;subprocess&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;PIPE&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; stderr&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;subprocess&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;PIPE&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; universal_newlines&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:24:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431721#M33942</guid>
      <dc:creator>JoshKalov</dc:creator>
      <dc:date>2021-12-11T19:24:42Z</dc:date>
    </item>
    <item>
      <title>Re: Execute Python 2 Code via Python 3</title>
      <link>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431722#M33943</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I was able to use &lt;SPAN style="font-family: courier new, courier, monospace;"&gt;os.startfile()&lt;/SPAN&gt; from both a Python 2 (ArcMap Python) and Python 3 (Pro Python) command prompt to open multiple MXDs in ArcMap.&amp;nbsp; I say this just to say it isn't an issue with os.startfile(), so resolving these errors might be a good step in resolving your larger issue.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 31 Dec 2019 16:18:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/execute-python-2-code-via-python-3/m-p/431722#M33943</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-12-31T16:18:47Z</dc:date>
    </item>
  </channel>
</rss>

