<?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 Python script works perfectly in ArcMap Python window and fails as Script Tool in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-script-works-perfectly-in-arcmap-python/m-p/835167#M3301</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a simple script to do the following: 1) convert an Excel file to a dBase file, 2) make an event layer from the dBase file, 3) convert the event layer to a feature class, and finally 4) apply symbology from a symbology layer. When I run this script in the Python window in ArcMap it works flawlessly every time (the result is that both the event layer and the new feature class are added to the Table of Contents). When I run it as a script tool it does successfully complete tasks 1-3, but it does not add the event layer or the feature class to the table of contents, and it throws the following error for applying symbology:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt; File "C:\Users\Karen\Desktop\script.py", line 13, in &amp;lt;module&amp;gt;&lt;BR /&gt; arcpy.ApplySymbologyFromLayer_management("trees", "trees_symbology.lyr")&lt;BR /&gt; File "c:\program files (x86)\arcgis\desktop10.6\arcpy\arcpy\management.py", line 6951, in ApplySymbologyFromLayer&lt;BR /&gt; raise e&lt;BR /&gt;ExecuteError: Failed to execute. Parameters are not valid.&lt;BR /&gt;ERROR 000732: Input Layer: Dataset trees does not exist or is not supported&lt;BR /&gt;Failed to execute (ApplySymbologyFromLayer).&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Does anyone know why it will work in the Python Script window but not as a script tool? Below is my script:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;arcpy.env.workspace = "C:\Users\Karen\Desktop\Using Urban ArcGis\Assignment 3"&lt;/P&gt;&lt;P&gt;arcpy.env.overwriteOutput = True&lt;/P&gt;&lt;P&gt;arcpy.ExcelToTable_conversion("trees.xls", "trees.gdb", "trees")&lt;/P&gt;&lt;P&gt;arcpy.MakeXYEventLayer_management("trees.dbf", "POINT_X", "POINT_Y", "trees_points")&lt;/P&gt;&lt;P&gt;arcpy.FeatureClassToFeatureClass_conversion("trees_points", "Week5.gdb", "trees")&lt;/P&gt;&lt;P&gt;arcpy.ApplySymbologyFromLayer_management("trees", "trees_symbology.lyr")&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 14 May 2019 16:02:46 GMT</pubDate>
    <dc:creator>KarenBlanco</dc:creator>
    <dc:date>2019-05-14T16:02:46Z</dc:date>
    <item>
      <title>Python script works perfectly in ArcMap Python window and fails as Script Tool</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-script-works-perfectly-in-arcmap-python/m-p/835167#M3301</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a simple script to do the following: 1) convert an Excel file to a dBase file, 2) make an event layer from the dBase file, 3) convert the event layer to a feature class, and finally 4) apply symbology from a symbology layer. When I run this script in the Python window in ArcMap it works flawlessly every time (the result is that both the event layer and the new feature class are added to the Table of Contents). When I run it as a script tool it does successfully complete tasks 1-3, but it does not add the event layer or the feature class to the table of contents, and it throws the following error for applying symbology:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt; File "C:\Users\Karen\Desktop\script.py", line 13, in &amp;lt;module&amp;gt;&lt;BR /&gt; arcpy.ApplySymbologyFromLayer_management("trees", "trees_symbology.lyr")&lt;BR /&gt; File "c:\program files (x86)\arcgis\desktop10.6\arcpy\arcpy\management.py", line 6951, in ApplySymbologyFromLayer&lt;BR /&gt; raise e&lt;BR /&gt;ExecuteError: Failed to execute. Parameters are not valid.&lt;BR /&gt;ERROR 000732: Input Layer: Dataset trees does not exist or is not supported&lt;BR /&gt;Failed to execute (ApplySymbologyFromLayer).&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Does anyone know why it will work in the Python Script window but not as a script tool? Below is my script:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;arcpy.env.workspace = "C:\Users\Karen\Desktop\Using Urban ArcGis\Assignment 3"&lt;/P&gt;&lt;P&gt;arcpy.env.overwriteOutput = True&lt;/P&gt;&lt;P&gt;arcpy.ExcelToTable_conversion("trees.xls", "trees.gdb", "trees")&lt;/P&gt;&lt;P&gt;arcpy.MakeXYEventLayer_management("trees.dbf", "POINT_X", "POINT_Y", "trees_points")&lt;/P&gt;&lt;P&gt;arcpy.FeatureClassToFeatureClass_conversion("trees_points", "Week5.gdb", "trees")&lt;/P&gt;&lt;P&gt;arcpy.ApplySymbologyFromLayer_management("trees", "trees_symbology.lyr")&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 May 2019 16:02:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-script-works-perfectly-in-arcmap-python/m-p/835167#M3301</guid>
      <dc:creator>KarenBlanco</dc:creator>
      <dc:date>2019-05-14T16:02:46Z</dc:date>
    </item>
    <item>
      <title>Re: Python script works perfectly in ArcMap Python window and fails as Script Tool</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-script-works-perfectly-in-arcmap-python/m-p/835168#M3302</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sharing with &lt;A href="https://community.esri.com/space/2145"&gt;Python&lt;/A&gt;‌ since this is an ArcPy question and not ArcGIS API for Python question.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 May 2019 17:00:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-script-works-perfectly-in-arcmap-python/m-p/835168#M3302</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2019-05-14T17:00:14Z</dc:date>
    </item>
    <item>
      <title>Re: Python script works perfectly in ArcMap Python window and fails as Script Tool</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-script-works-perfectly-in-arcmap-python/m-p/835169#M3303</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Joshua!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 May 2019 19:09:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-script-works-perfectly-in-arcmap-python/m-p/835169#M3303</guid>
      <dc:creator>KarenBlanco</dc:creator>
      <dc:date>2019-05-14T19:09:12Z</dc:date>
    </item>
    <item>
      <title>Re: Python script works perfectly in ArcMap Python window and fails as Script Tool</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-script-works-perfectly-in-arcmap-python/m-p/835170#M3304</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Karen... If you examine your path, it needs to be 'raw' encoded.&amp;nbsp; In python 3, it fails miserably rather than quietly failing with a useless message&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;pth &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"C:\Users\Karen\Desktop\Using Urban ArcGis\Assignment 3"&lt;/SPAN&gt;
  File &lt;SPAN class="string token"&gt;"&amp;lt;ipython-input-1-59b8c5700c1b&amp;gt;"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; line &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;
    pth &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"C:\Users\Karen\Desktop\Using Urban ArcGis\Assignment 3"&lt;/SPAN&gt;
         &lt;SPAN class="operator token"&gt;^&lt;/SPAN&gt;
SyntaxError&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;unicode error&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'unicodeescape'&lt;/SPAN&gt; codec can't decode bytes &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; position &lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;3&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; truncated \UXXXXXXXX escape&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;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But don't use spaces in folders, it will just cause no end of grief in other situations.&lt;/P&gt;&lt;P&gt;So to see if you can get past the error message, put the little 'r' in front of the path&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;pth &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;"C:\Users\Karen\Desktop\Using Urban ArcGis\Assignment 3"&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;pth&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
C&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;\Users\Karen\Desktop\Using Urban ArcGis\Assignment &lt;SPAN class="number token"&gt;3&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>Sun, 12 Dec 2021 10:07:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-script-works-perfectly-in-arcmap-python/m-p/835170#M3304</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-12T10:07:54Z</dc:date>
    </item>
  </channel>
</rss>

