Running arcpy script from Powershell after updating to ArcGIS Pro 3.1.0 gives error

5450
31
02-26-2023 08:27 PM
KevinCheriyan
Occasional Contributor

I have been running my python script that uses arcpy, from Powershell without any problems. But in the middle of a session, I thought to update ArcGIS Pro from 3.0.1 to 3.1 and my script immediately stopped working. I run my script from Powershell using propy (the propy.bat file location is added to my environmental variables). The following error is produced:

 

Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'ArcGIS.Core, Version=13.1.0.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86'. The system cannot find the file specified.
File name: 'ArcGIS.Core, Version=13.1.0.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86'
   at ArcGIS.Core.Internal.PluginWorkspaceFactoryShim.FinalConstruct(PluginWorkspaceFactoryShim* )
   at ATL.CComPolyObject<ArcGIS::Core::Internal::PluginWorkspaceFactoryShim>.FinalConstruct(CComPolyObject<ArcGIS::Core::Internal::PluginWorkspaceFactoryShim>* )
   at ATL.CComPolyObject<ArcGIS::Core::Internal::PluginWorkspaceFactoryShim>.CreateInstance(IUnknown* pUnkOuter, CComPolyObject<ArcGIS::Core::Internal::PluginWorkspaceFactoryShim>** pp)
   at ArcGIS.Core.Internal.PluginWorkspaceFactoryShim.CreateInstance(IAddInRecord* pAddinRecord, IUnknown* controllingUnknown, IUnknown** ppPluginWorkspaceFactory)
   at PluginFactory.CreateObject(PluginFactory* , IAddInRecord* pAddinRecord, IUnknown* pUnkOuter, IUnknown** ppPluginWorkspaceFactory)

 

This only happens when a method that takes a file name or location as a parameter is run. For instance, the following doesn't produce an error:

 

arcpy.env.overwriteOutput = True // no error

 

But this does:

 

arcpy.env.workspace = "location of gdb" //error

 

and so does this:

 

arcpy.Exists("location of gdb that exists") //error

 

but the following doesn't produce an error; just prints False.

 

arcpy.Exists("") //no error

 

I've tried restarting my Windows and rechecking environmental variables in Systems Settings. The same commands run fine from within ArcGIS Pro's python window. As far as I could tell, this started happening after I upgraded to Pro 3.1

Anyone have any idea what could be wrong here? I need to use propy or python to run my script from the shell.

Both python or propy commands from shell give same error


--------------------------------------------------
Application Developer, GeoMarvel
31 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

@Gerry_S  In ArcGIS Desktop (ArcMap, ArcCatalog, etc.) you needed to install the SDK in order to be able to use the API, however, in ArcGIS Pro the API is part of the ArcGIS Pro installation.   ArcGIS.Core is one of the core assemblies used by ArcGIS Pro.   When you install the Pro SDK in Visual Studio you only get the Project / Item templates and some utilities to manage your Pro SDK add-ins & configuration projects.  The Pro SDK doesn't install any part of the API since it's part of ArcGIS Pro (actually ArcGIS Pro is using this API as well).  When running a python script, arcpy is also trying to use the ArcGIS Pro API (which ArcGIS.Core is part of) but can't find the assembly.  This worked in 3.0 so i assume there is part of the environment that tells arcpy where to find the Pro assemblies changed in 3.1.   

KevinCheriyan
Occasional Contributor

Does downgrading to Pro 3.0.x solve the issue? I'm hesitant to go through the effort so far until I know this can solve it for sure


--------------------------------------------------
Application Developer, GeoMarvel
0 Kudos
ShaunWalbridge
Esri Regular Contributor

Does your Python script work from the command line without the Pro SDK installed? It'd be good to see if this only happens specifically in an interaction with that component or is more broadly occurring. Thanks!

KevinCheriyan
Occasional Contributor

I will try to find some time in the next couple of days to do this @ShaunWalbridge . Before I uninstall the Pro SDK, I need to tie up a few loose ends in the Pro SDK project I'm working on 😅


--------------------------------------------------
Application Developer, GeoMarvel
0 Kudos
ShaunWalbridge
Esri Regular Contributor

Got it. That would be great, once we have a clear set of interactions causing this we can get a reproducible case together and start debugging it. I don't think we have had anything like this happen before and wouldn't normally expect any interaction between the two "worlds" of .NET and Python.

KevinCheriyan
Occasional Contributor

I uninstalled the Pro SDK and related extensions from Visual Studio, restarted my machine and tried running the same script from Powershell. Much to my surprise, this gives me the same error. I still have Pro installed.


--------------------------------------------------
Application Developer, GeoMarvel
0 Kudos
ShaunWalbridge
Esri Regular Contributor

Have you tried removing the plugins as Wolf described? Based on our internal testing, this is the cause of the issue, we are working toward a solution but don't have something available in software yet.

 

0 Kudos
KristinBlier
New Contributor III

I'm also running into this. So, at least for now with ArcGIS Pro 3.1, you can't use arcpy if you have plugin datasource Add-In's installed?  This is specific to version 3.1, and 3.0 does not have this limitation?

0 Kudos
KristinBlier
New Contributor III

Is there any update on this Shaun?  I tried reporting this issue with Esri support, but its feels like I'm jumping through hoops to get a bug filed. You can reproduce this with the ProDataReader in the Esri pro SDK community samples. 

0 Kudos
ShaunWalbridge
Esri Regular Contributor

There should be a patch coming out later this month which addresses this issue for Pro 3.1 by disabling the add-in data sources from Python code and will work again without needing to delete anything. This issue has an associated bug, at BUG-000157823 that also can be tracked.

Best of luck! Shaun