Select to view content in your preferred language

Strange problem when run a script from other script

421
3
07-11-2023 06:07 AM
mody_buchbinder
Occasional Contributor III

I have script a.py that have one line:

arcpy.env.workspace = r"C:\temp"

I am running this script with the line:

proc = subprocess.Popen([r"C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe", r"D:\temp\a.py"])

When I run it from the python window in Pro 3.1 it runs with no error.

When I create script b.py that have only this line and make a tool out of it I get the error the GPEnvironment

have no method workspace

This works good in Pro 2.X

Thanks

Mody

0 Kudos
3 Replies
AzinSharaf
Occasional Contributor II

don't you need to `import arcpy`? The python window in arcgis pro doesn't need `import arcpy` since it is already imported by launching the application. 

0 Kudos
mody_buchbinder
Occasional Contributor III

The original code has all the needed import statements.

I just did not want to put extra lines in my post.

0 Kudos
mody_buchbinder
Occasional Contributor III

Just did some more testing.

The "workspace" line fail even if I run it using a bat file or replace subprocess.popen with os.system.

As I say it runs from all options, direct from IDLE or from pro python window but not when I define it as a tool.

And the strangest thing - the line arcpy.env.overwriteOutput = True does work. I did not tried other env's but it looks only the workspace have a problem.

0 Kudos