<?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: OSError: Script tool fails when ran from another PC/instance of Pro in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/oserror-script-tool-fails-when-ran-from-another-pc/m-p/1540036#M72897</link>
    <description>&lt;P&gt;You're combining os.path and pathlib, you can join a path inline with pathlib like so:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from pathlib import Path

#workspace folder
arcpy.env.workspace = arcpy.GetParameterAsText(0)
env = Path(arcpy.env.workspace)
...
current_aprx = arcpy.mp.ArcGISProject(env / file)
# Or with a methodcall
current_aprx = arcpy.mp.ArcGISProject(env.joinpath(file))&lt;/LI-CODE&gt;&lt;P&gt;The only reason I'm suggesting pathlib is because it gives a lot more control over the your paths. You can resolve it to posix or uri formats. If you're using a UNC path format you might need to play around with it. Pathlib will normalize the input string for you, but I think using joinpath or / will skip normalization.&lt;/P&gt;&lt;P&gt;Whatever is happening it seems like you're generating a valid UNC path that the os.path and pathlib modules like, but are feeding it in a weird format to the ArcGISProject function.&lt;/P&gt;</description>
    <pubDate>Wed, 18 Sep 2024 16:57:04 GMT</pubDate>
    <dc:creator>HaydenWelch</dc:creator>
    <dc:date>2024-09-18T16:57:04Z</dc:date>
    <item>
      <title>OSError: Script tool fails when ran from another PC/instance of Pro</title>
      <link>https://community.esri.com/t5/python-questions/oserror-script-tool-fails-when-ran-from-another-pc/m-p/1538559#M72851</link>
      <description>&lt;P&gt;I have a simple custom script tool that I want to share within our GIS office. The tool works fine from in my Pro application. Both the tool and the stand alone script it points to are stored in a network folder/UNC path that everyone has access to. When ran from another instance of Pro, whether from my colleague's PC or a dedicated box I remote log into, the tool throws this error:&lt;/P&gt;&lt;PRE&gt; Traceback (most recent call last):
  File "\\uncpathtothescript\LayoutToPDF_Tool.py", line 26, in &amp;lt;module&amp;gt;
    current_aprx = arcpy.mp.ArcGISProject(os.path.join(env, file))
  File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\_mp.py", line 337, in __init__
    self._arc_object = arcgisscripting._mapping.ArcGISProject(*gp_fixargs((aprx_path,), True))
OSError: \\uncpathtoproproject\COUNTY_BOARD_A.aprx
 Failed to execute (LayoutToPDFs).&lt;/PRE&gt;&lt;P&gt;I haven't debugged other than running the tool on different machines. I've read you can share to Enterprise Portal, but I'm not interested in that. If I can simply share to a network folder so anyone can just simply open it immediately from their system that would be best.&lt;/P&gt;&lt;P&gt;The tool exports layouts to PDFs.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#-------------------------------------------------------------------------------
# Name:        LayoutToPDF_Tool.py
# Purpose:     Exports APRX layout to PDF.
#
# Author:      jpilbeam
#
# Created:     13/08/2024
# Copyright:   (c) Will Co GIS
# Licence:     &amp;lt;WillCo GIS&amp;gt;
#-------------------------------------------------------------------------------

import arcpy, os

#workspace folder
env = arcpy.env.workspace = arcpy.GetParameterAsText(0)
#print the number of aprx files in the workspace folder
aprxlist = arcpy.ListFiles("*.aprx")
arcpy.AddMessage("Currently {0} maps to be updated:\n".format(len(aprxlist)))

#Loop through folder and list APRXs
for dirName, subdirList, fileList in os.walk(env):
    for file in fileList:
        if file.endswith(".aprx"):
            current_aprx = arcpy.mp.ArcGISProject(os.path.join(env, file))
                       
            for lyt in current_aprx.listLayouts():
                #export APRXs to PDFs
                lyt.exportToPDF(f'{env}\{lyt.name}')
                arcpy.AddMessage("{} to PDF".format(lyt.name))

# current_aprx.save()
del current_aprx
print("----done----")&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 13 Sep 2024 20:42:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/oserror-script-tool-fails-when-ran-from-another-pc/m-p/1538559#M72851</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2024-09-13T20:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: OSError: Script tool fails when ran from another PC/instance of Pro</title>
      <link>https://community.esri.com/t5/python-questions/oserror-script-tool-fails-when-ran-from-another-pc/m-p/1538631#M72854</link>
      <description>&lt;P&gt;Have you tried formatting the path using pathlib? Whatever is happening seems to be related to the UNC path, and pathlib has some more tools for dealing with paths that aren't just drive letters and directories.&lt;/P&gt;&lt;P&gt;Could also be a user permission error?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2024 23:57:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/oserror-script-tool-fails-when-ran-from-another-pc/m-p/1538631#M72854</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2024-09-13T23:57:19Z</dc:date>
    </item>
    <item>
      <title>Re: OSError: Script tool fails when ran from another PC/instance of Pro</title>
      <link>https://community.esri.com/t5/python-questions/oserror-script-tool-fails-when-ran-from-another-pc/m-p/1538874#M72861</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/294090"&gt;@JaredPilbeam2&lt;/a&gt;&amp;nbsp;does the tool fail from the client machine when you specify the workspace folder with a drive letter that is local/mapped to that same client machine?&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2024 13:13:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/oserror-script-tool-fails-when-ran-from-another-pc/m-p/1538874#M72861</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-09-16T13:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: OSError: Script tool fails when ran from another PC/instance of Pro</title>
      <link>https://community.esri.com/t5/python-questions/oserror-script-tool-fails-when-ran-from-another-pc/m-p/1538928#M72862</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/10527"&gt;@JakeSkinner&lt;/a&gt;Yes. I just ran the tool with a test folder as a workspace on the remote machine's C drive. The result was the same OSError.&lt;BR /&gt;&lt;BR /&gt;I'm looking into pathlib. Thanks for the suggestion &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/607017"&gt;@HaydenWelch&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2024 14:28:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/oserror-script-tool-fails-when-ran-from-another-pc/m-p/1538928#M72862</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2024-09-16T14:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: OSError: Script tool fails when ran from another PC/instance of Pro</title>
      <link>https://community.esri.com/t5/python-questions/oserror-script-tool-fails-when-ran-from-another-pc/m-p/1538972#M72863</link>
      <description>&lt;P&gt;Unless I didn't use Path properly, the script tool failed with the same OSError on the same line as before.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from pathlib import Path

#workspace folder
arcpy.env.workspace = arcpy.GetParameterAsText(0)
env = Path(arcpy.env.workspace)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;line 26 (the line it's been failing on):&lt;/P&gt;&lt;LI-CODE lang="python"&gt;current_aprx = arcpy.mp.ArcGISProject(os.path.join(env, file))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2024 15:41:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/oserror-script-tool-fails-when-ran-from-another-pc/m-p/1538972#M72863</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2024-09-16T15:41:30Z</dc:date>
    </item>
    <item>
      <title>Re: OSError: Script tool fails when ran from another PC/instance of Pro</title>
      <link>https://community.esri.com/t5/python-questions/oserror-script-tool-fails-when-ran-from-another-pc/m-p/1539095#M72865</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/10527"&gt;@JakeSkinner&lt;/a&gt;I slightly misunderstood your reply the first time. I just tried running the tool from the remote box again. This time in the workspace parameter I used a mapped letter drive. It still resulted in the same OSError.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2024 19:16:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/oserror-script-tool-fails-when-ran-from-another-pc/m-p/1539095#M72865</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2024-09-16T19:16:41Z</dc:date>
    </item>
    <item>
      <title>Re: OSError: Script tool fails when ran from another PC/instance of Pro</title>
      <link>https://community.esri.com/t5/python-questions/oserror-script-tool-fails-when-ran-from-another-pc/m-p/1539103#M72866</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/294090"&gt;@JaredPilbeam2&lt;/a&gt;&amp;nbsp;are you able to open the Pro Project and save changes to it when logged into the remote server?&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2024 19:31:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/oserror-script-tool-fails-when-ran-from-another-pc/m-p/1539103#M72866</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-09-16T19:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: OSError: Script tool fails when ran from another PC/instance of Pro</title>
      <link>https://community.esri.com/t5/python-questions/oserror-script-tool-fails-when-ran-from-another-pc/m-p/1539147#M72869</link>
      <description>&lt;P&gt;It's not a remote server, just a remote computer. I'm just using the catalog pane in a random Pro project while testing as I'm sure my colleagues will be opening random projects in the future to use the tool. But, to answer you question: Yes, I can open and save the same Pro project on the remote computer as well as mine.&lt;BR /&gt;&lt;BR /&gt;I noticed my tools were in .tbx format. I'm going to create an .atbx and transfer the tool(s) over then&amp;nbsp; try again.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2024 20:15:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/oserror-script-tool-fails-when-ran-from-another-pc/m-p/1539147#M72869</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2024-09-16T20:15:13Z</dc:date>
    </item>
    <item>
      <title>Re: OSError: Script tool fails when ran from another PC/instance of Pro</title>
      <link>https://community.esri.com/t5/python-questions/oserror-script-tool-fails-when-ran-from-another-pc/m-p/1539170#M72870</link>
      <description>&lt;P&gt;That seems to have solved the problem, at least on the remote computer. I also updated Pro to the latest (3.3.1) on that machine. It completed with no error. However, then I had a colleague run the tool and it still throws an OSError on his machine. Now the error is on a different line, only:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;lyt.exportToPDF(f'{env}\{lyt.name}')&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 16 Sep 2024 20:44:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/oserror-script-tool-fails-when-ran-from-another-pc/m-p/1539170#M72870</guid>
      <dc:creator>JaredPilbeam2</dc:creator>
      <dc:date>2024-09-16T20:44:27Z</dc:date>
    </item>
    <item>
      <title>Re: OSError: Script tool fails when ran from another PC/instance of Pro</title>
      <link>https://community.esri.com/t5/python-questions/oserror-script-tool-fails-when-ran-from-another-pc/m-p/1540036#M72897</link>
      <description>&lt;P&gt;You're combining os.path and pathlib, you can join a path inline with pathlib like so:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from pathlib import Path

#workspace folder
arcpy.env.workspace = arcpy.GetParameterAsText(0)
env = Path(arcpy.env.workspace)
...
current_aprx = arcpy.mp.ArcGISProject(env / file)
# Or with a methodcall
current_aprx = arcpy.mp.ArcGISProject(env.joinpath(file))&lt;/LI-CODE&gt;&lt;P&gt;The only reason I'm suggesting pathlib is because it gives a lot more control over the your paths. You can resolve it to posix or uri formats. If you're using a UNC path format you might need to play around with it. Pathlib will normalize the input string for you, but I think using joinpath or / will skip normalization.&lt;/P&gt;&lt;P&gt;Whatever is happening it seems like you're generating a valid UNC path that the os.path and pathlib modules like, but are feeding it in a weird format to the ArcGISProject function.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 16:57:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/oserror-script-tool-fails-when-ran-from-another-pc/m-p/1540036#M72897</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2024-09-18T16:57:04Z</dc:date>
    </item>
  </channel>
</rss>

