<?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 Problem with running python with even only import arcpy from C# Web API in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/problem-with-running-python-with-even-only-import/m-p/1140778#M63660</link>
    <description>&lt;P&gt;We met problem with running python file.&amp;nbsp; I am not sure if we have did wrong with any environment setting.&lt;/P&gt;&lt;P&gt;ArcGIS Pro 2.8 installed with arcpy&lt;/P&gt;&lt;P&gt;1. A c# API calls a batch file&lt;/P&gt;&lt;P&gt;2. Then, the batch file calls a python script&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Problem happened that it all failed with no return when arcpy import included.&lt;/STRONG&gt; But, we can run successfully with no arcpy included. So, we verified that python can be executed when without arcpy.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Code for c# API&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Process p = new Process();&lt;BR /&gt;p.StartInfo = new ProcessStartInfo()&lt;BR /&gt;{&lt;BR /&gt;//start.WorkingDirectory = @"D:\script",&lt;BR /&gt;FileName = @"D:\script\pythontest.bat",&lt;BR /&gt;Arguments = "",&lt;BR /&gt;RedirectStandardOutput = true,&lt;BR /&gt;UseShellExecute = false,&lt;BR /&gt;CreateNoWindow = true&lt;BR /&gt;};&lt;BR /&gt;p.Start();&lt;BR /&gt;string output = p.StandardOutput.ReadToEnd();&lt;BR /&gt;p.WaitForExit();&lt;BR /&gt;Log.Information("python output=" + output);&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Code for pythontest.bat batch file&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;"C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\propy" myscript.py&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Code for&amp;nbsp;myscript.py&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;import sys&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 04 Feb 2022 14:53:24 GMT</pubDate>
    <dc:creator>WilliamYip</dc:creator>
    <dc:date>2022-02-04T14:53:24Z</dc:date>
    <item>
      <title>Problem with running python with even only import arcpy from C# Web API</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-running-python-with-even-only-import/m-p/1140778#M63660</link>
      <description>&lt;P&gt;We met problem with running python file.&amp;nbsp; I am not sure if we have did wrong with any environment setting.&lt;/P&gt;&lt;P&gt;ArcGIS Pro 2.8 installed with arcpy&lt;/P&gt;&lt;P&gt;1. A c# API calls a batch file&lt;/P&gt;&lt;P&gt;2. Then, the batch file calls a python script&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Problem happened that it all failed with no return when arcpy import included.&lt;/STRONG&gt; But, we can run successfully with no arcpy included. So, we verified that python can be executed when without arcpy.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Code for c# API&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Process p = new Process();&lt;BR /&gt;p.StartInfo = new ProcessStartInfo()&lt;BR /&gt;{&lt;BR /&gt;//start.WorkingDirectory = @"D:\script",&lt;BR /&gt;FileName = @"D:\script\pythontest.bat",&lt;BR /&gt;Arguments = "",&lt;BR /&gt;RedirectStandardOutput = true,&lt;BR /&gt;UseShellExecute = false,&lt;BR /&gt;CreateNoWindow = true&lt;BR /&gt;};&lt;BR /&gt;p.Start();&lt;BR /&gt;string output = p.StandardOutput.ReadToEnd();&lt;BR /&gt;p.WaitForExit();&lt;BR /&gt;Log.Information("python output=" + output);&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Code for pythontest.bat batch file&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;"C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\propy" myscript.py&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Code for&amp;nbsp;myscript.py&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;import sys&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 14:53:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-running-python-with-even-only-import/m-p/1140778#M63660</guid>
      <dc:creator>WilliamYip</dc:creator>
      <dc:date>2022-02-04T14:53:24Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with running python with even only import arcpy from C# Web API</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-running-python-with-even-only-import/m-p/1140858#M63661</link>
      <description>&lt;P&gt;What license do you have for the Pro installation?&amp;nbsp; arcpy also has to be licensed, so it may be failing on not being able to be licensed.&amp;nbsp; You can wrap the imports into a try/except and log the exception that happens when it tries to import arcpy.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 17:47:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-running-python-with-even-only-import/m-p/1140858#M63661</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-02-04T17:47:50Z</dc:date>
    </item>
  </channel>
</rss>

