ArcGIS Pro ignoring arcpy.env.workspace

1293
4
04-08-2020 06:24 AM
SjoerdHoekstra
New Contributor

Hi, im busy debugging a tool in ArcGIS Pro. 

The tool works fine in ArcGIS Desktop or via Python itself (based on Desktop or Pro). I just noticed that my tool doesn't work right when I run it within ArcGIS Pro. The problem seems to be that within a ArcGIS Pro project the code in the tool is ignored, so arcpy.env.workspace = 'my_desired_workspace' is ignored and data is written to the default.gdb of the project. Is this a bug Esri is already aware of? Or can I do something to prevent it? 

Like for example the tool arcpy.ListRasters() is not working correctly now because it is not checking the right workspace. 

By the way I think it might be working correctly for vectordatasets, but for the rasters it is not working right for me. 


Hopefully someone can help me! 

0 Kudos
4 Replies
JoshuaBixby
MVP Esteemed Contributor

I just ran a quick Python script tool where I set the workspace similar to you and ran ListRasters, and it worked fine.  I am using Pro 2.5, not sure if it is version thing. 

0 Kudos
SjoerdHoekstra
New Contributor

Hi Joshua, 

Thanks for the quick reply.

I actually found out that the ListRasters does work well. It didnt work because the raster that I was looking for was written to the default.gdb because the arcpy.env.workspace did not seem to work. When you set it to arpcy.env.workspace and save a raster to a location does it end up in the right location? or in your default gdb as well?

0 Kudos
DanPatterson_Retired
MVP Emeritus

It could be that you are not using the recommended *.tif format for rasters.

If you are running outside of Pro, there should be no workspace or scratchWorkspace, as shown below.

What was your initial and desired workspaces?

import arcpy

print(arcpy.env.workspace)
None

arcpy.env.workspace = r"C:\Data\rasters"

print(arcpy.env.workspace)
C:\Data\rasters

rs = arcpy.ListRasters()

print(rs)
['2.png', 'rasters_100sq00.tif', 'rasters_100sq01.tif',
 ...big snip...
'rasters_100sq29.tif', 'rasters_100sq30.tif']

From ....

ListRasters—ArcPy Functions | Documentation 

note that the env.workspace is the 'current' workspace and not a project o scratch workspace.

When working outside of Pro any of the "List*** " functions behave as I expect.

0 Kudos
thiaggotayer1
New Contributor

I'm having the same problem where ArcGIS Pro is totally ignoring the arcpy.env.scratchWorkspace. It is sending all my temporary files to ArcGIS default local temp folder.

When I print arcpy.env.scratchWorkspace and arcpy.env.workspace it gives back the correct paths, but when I run any tools such as arcpy.CalculateStatistics_management() the temp output goes to the default ArcGIS temp folder and not the scratch workspace that I want.

0 Kudos