<?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 Script runs manually but fails in automated task due to directory error in ArcGIS Notebooks Questions</title>
    <link>https://community.esri.com/t5/arcgis-notebooks-questions/script-runs-manually-but-fails-in-automated-task/m-p/1609884#M917</link>
    <description>&lt;P&gt;I have a Python script in an ArcGIS Online Jupyter Notebook that processes GeoJSON data and saves a CSV file. It works perfectly when I run it cell-by-cell manually. However, when scheduling it as an automated task (e.g., every 15 minutes), it fails with this error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OSError: Cannot save file into a non-existent directory: '/arcgis/home/nextbike'&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import pandas as pd

# Load GeoJSON data
features = geojson_data['features']

# Extract desired columns including coordinates
data = []
for feature in features:
    properties = feature['properties']
    id = properties.get('id')
    typ_stojanu = properties.get('typ_stojanu')
    coordinates = feature['geometry']['coordinates']
    x = coordinates[0]
    y = coordinates[1]
    data.append({'id': id, 'typ_stojanu': typ_stojanu, 'x': x, 'y': y})

# Convert to DataFrame
df = pd.DataFrame(data)

# Save to CSV
csv_file = r"/arcgis/home/nextbike/filtered_data.csv"
df.to_csv(csv_file, index=False)&lt;/LI-CODE&gt;&lt;P class=""&gt;&lt;STRONG&gt;Problem:&lt;/STRONG&gt;&lt;/P&gt;&lt;UL class=""&gt;&lt;LI&gt;&lt;P class=""&gt;The folder&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;/arcgis/home/nextbike&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;exists when I run the notebook manually.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P class=""&gt;The automated task fails at&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;df.to_csv()&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;with the directory error, even though the folder appears to exist.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P class=""&gt;&lt;STRONG&gt;What I’ve Tried:&lt;/STRONG&gt;&lt;/P&gt;&lt;UL class=""&gt;&lt;LI&gt;&lt;P class=""&gt;Confirmed the folder exists manually.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P class=""&gt;Another script with explicit directory creation works (see below).&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P class=""&gt;&lt;STRONG&gt;Working Example:&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os

folder_path = r"/arcgis/home/nabijecky"
os.makedirs(folder_path, exist_ok=True)
df.to_csv(os.path.join(folder_path, "file.csv"))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Question:&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Why does the automated task fail to recognize the directory, and how can I fix this?&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Apr 2025 06:21:40 GMT</pubDate>
    <dc:creator>JiříKomínek</dc:creator>
    <dc:date>2025-04-29T06:21:40Z</dc:date>
    <item>
      <title>Script runs manually but fails in automated task due to directory error</title>
      <link>https://community.esri.com/t5/arcgis-notebooks-questions/script-runs-manually-but-fails-in-automated-task/m-p/1609884#M917</link>
      <description>&lt;P&gt;I have a Python script in an ArcGIS Online Jupyter Notebook that processes GeoJSON data and saves a CSV file. It works perfectly when I run it cell-by-cell manually. However, when scheduling it as an automated task (e.g., every 15 minutes), it fails with this error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OSError: Cannot save file into a non-existent directory: '/arcgis/home/nextbike'&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import pandas as pd

# Load GeoJSON data
features = geojson_data['features']

# Extract desired columns including coordinates
data = []
for feature in features:
    properties = feature['properties']
    id = properties.get('id')
    typ_stojanu = properties.get('typ_stojanu')
    coordinates = feature['geometry']['coordinates']
    x = coordinates[0]
    y = coordinates[1]
    data.append({'id': id, 'typ_stojanu': typ_stojanu, 'x': x, 'y': y})

# Convert to DataFrame
df = pd.DataFrame(data)

# Save to CSV
csv_file = r"/arcgis/home/nextbike/filtered_data.csv"
df.to_csv(csv_file, index=False)&lt;/LI-CODE&gt;&lt;P class=""&gt;&lt;STRONG&gt;Problem:&lt;/STRONG&gt;&lt;/P&gt;&lt;UL class=""&gt;&lt;LI&gt;&lt;P class=""&gt;The folder&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;/arcgis/home/nextbike&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;exists when I run the notebook manually.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P class=""&gt;The automated task fails at&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;df.to_csv()&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;with the directory error, even though the folder appears to exist.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P class=""&gt;&lt;STRONG&gt;What I’ve Tried:&lt;/STRONG&gt;&lt;/P&gt;&lt;UL class=""&gt;&lt;LI&gt;&lt;P class=""&gt;Confirmed the folder exists manually.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P class=""&gt;Another script with explicit directory creation works (see below).&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P class=""&gt;&lt;STRONG&gt;Working Example:&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os

folder_path = r"/arcgis/home/nabijecky"
os.makedirs(folder_path, exist_ok=True)
df.to_csv(os.path.join(folder_path, "file.csv"))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Question:&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Why does the automated task fail to recognize the directory, and how can I fix this?&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Apr 2025 06:21:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-notebooks-questions/script-runs-manually-but-fails-in-automated-task/m-p/1609884#M917</guid>
      <dc:creator>JiříKomínek</dc:creator>
      <dc:date>2025-04-29T06:21:40Z</dc:date>
    </item>
    <item>
      <title>Re: Script runs manually but fails in automated task due to directory error</title>
      <link>https://community.esri.com/t5/arcgis-notebooks-questions/script-runs-manually-but-fails-in-automated-task/m-p/1609894#M918</link>
      <description>&lt;P&gt;AGOL Notebooks have always been iffy for me. A couple things you could try -&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Navigate to the directory using os.chdir() then call the to_csv() method using a relative path. This may work since you have been able to successfully interact with the directory structure using OS.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import pandas as pd
import os

# Load GeoJSON data
features = geojson_data['features']

# Extract desired columns including coordinates
data = []
for feature in features:
    properties = feature['properties']
    id = properties.get('id')
    typ_stojanu = properties.get('typ_stojanu')
    coordinates = feature['geometry']['coordinates']
    x = coordinates[0]
    y = coordinates[1]
    data.append({'id': id, 'typ_stojanu': typ_stojanu, 'x': x, 'y': y})

# Convert to DataFrame
df = pd.DataFrame(data)

# Save to CSV
path = "/arcgis/home/nextbike/"
os.chdir(path)
csv_file = "filtered_data.csv"
df.to_csv(csv_file, index=False)&lt;/LI-CODE&gt;&lt;P&gt;2. Construct the full path using os.path.join(). This should not be functionally any different from how you have hardcoded the full path, but may prevent failure during compiling since it will handle the system preference on path construction.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import pandas as pd
import os

# Load GeoJSON data
features = geojson_data['features']

# Extract desired columns including coordinates
data = []
for feature in features:
    properties = feature['properties']
    id = properties.get('id')
    typ_stojanu = properties.get('typ_stojanu')
    coordinates = feature['geometry']['coordinates']
    x = coordinates[0]
    y = coordinates[1]
    data.append({'id': id, 'typ_stojanu': typ_stojanu, 'x': x, 'y': y})

# Convert to DataFrame
df = pd.DataFrame(data)

# Save to CSV
path = "/arcgis/home/nextbike
csv_file = "filtered_data.csv"
save_path = os.path.join(path, csv_file)
df.to_csv(save_path, index=False)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Apr 2025 10:44:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-notebooks-questions/script-runs-manually-but-fails-in-automated-task/m-p/1609894#M918</guid>
      <dc:creator>AustinAverill</dc:creator>
      <dc:date>2025-04-29T10:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: Script runs manually but fails in automated task due to directory error</title>
      <link>https://community.esri.com/t5/arcgis-notebooks-questions/script-runs-manually-but-fails-in-automated-task/m-p/1610341#M920</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/39532"&gt;@JiříKomínek&lt;/a&gt;&amp;nbsp;when configuring the scheduled task, check on the&amp;nbsp;&lt;STRONG&gt;Use workspace&lt;/STRONG&gt; option:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JakeSkinner_1-1746015907167.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/131175iD84D7B600C46C821/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JakeSkinner_1-1746015907167.png" alt="JakeSkinner_1-1746015907167.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Apr 2025 12:25:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-notebooks-questions/script-runs-manually-but-fails-in-automated-task/m-p/1610341#M920</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2025-04-30T12:25:14Z</dc:date>
    </item>
  </channel>
</rss>

