0

I'm trying to find a way to access the path of the notebook file (.ipynb) that I'm currently editing, in a way that would work either in ArcGIS Pro or in an external IDE like Jupyter or VS-code. What I've done in the past, with ArcGIS Pro 2.8 (and possibly 2.9), is to use os.getcwd()to provide the folder that the current file being edited is in. This works in an external IDE but doesn't work in ArcGIS Pro anymore, which can return various things, but often returns:

'C:\\WINDOWS\\system32'

In Pro, but not in an external IDE, something like the following will work, at least with the default workspace location, to provide the project folder:

os.path.dirname(arcpy.env.workspace)

However the same method will not work when editing the file with an external IDE like VS-code or Jupyter, since there's no knowledge of the default workspace for the project, and indeed there's no knowledge of the ArcGIS Pro project at all: our file is just sitting in a folder.

While a bit clunky, a liberal use of the os.path module may have the solution for identifying the path to the project folder. This seems to work in either environment:

os.path.dirname(os.path.realpath(arcpy.env.workspace))

So this may work since I purposefully standardize on editing these notebook files in the project folder (a slightly modified logic would work if I used a 'source' or 'notebooks' folder within the project folder just to keep things organized), to keep things simple for students; they can do things differently if they need to down the road as they get more comfortable.

So I may have answered my question, at least when standardizing on the project folder, or using relative paths from that. But I'm curious if there are other solutions to the basic question "Where is what I'm editing?"

Environment: [ArcGIS Pro 3.0.3, installed on my computer for all users, not just my user profile; Windows 10]

I posted a similar question to the Esri Community, but no solutions yet: https://community.esri.com/t5/arcgis-pro-questions/where-is-what-i-m-editing/m-p/1245910#M64035

1
  • If I understand correctly, you are looking for where the notebook is stored within your environment (the source file). Navigate to your installation directory, then \ArcGIS\Pro\bin\Python\envs\YOUR_ENV\Scripts\YOUR_NOTEBOOK.ipynb. In my case (a single user installation) the complete path is C:\Users\me\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\Scripts\notebook.ipynb Apr 4, 2023 at 13:26

1 Answer 1

0

The problem was solved. It turns out that os.getcwd() will work consistently to provide the ArcGIS Pro project folder as long as the os is starting there. The times these doesn't work when you're running code in ArcGIS Pro itself is when you start the program from the Start menu; if you always start it by opening the project document .aprx file, the os will have the correct path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.