Select to view content in your preferred language

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

5863
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
ShaunWalbridge
Esri Regular Contributor

Hello Kevin,

Could you provide some information on how you start PowerShell and whether you have any integration with e.g. Python.NET being used? When I start a new Windows Terminal session with Powershell, I can use the scripts and it seems to work without issue. I wouldn't expect to see .NET exceptions being raised from a Python perspective, so am not sure where these are entering into the picture.

Cheers,
Shaun

KevinCheriyan
Occasional Contributor

Hi @ShaunWalbridge ,

Thank you for your reply. Testing further, this issue can be replicated for me in Powershell, Command Prompt or any other shell. If I can start python in the shell, then import arcpy and run any command that requires a filepath, the above error is produced. 

I do separate work with the Pro SDK for .NET and some other Maps SDK for .NET projects, but I don't use console or shell for them, if that answers your question.

Thanks!


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

Got it. It sounds like there may be some cross-talk between ArcPy and the .NET SDK that I'm not aware of. Do you have the Pro 3.1 version of the Pro SDK installed? I might check that is installed, and see if it has an effect. Also, see if (temporarily) uninstalling the Maps SDK changes things.

JuliusDobravolskas
New Contributor

Hi,
I can add up to this issues. Simple example of listing domains from here: https://pro.arcgis.com/en/pro-app/latest/arcpy/data-access/listdomains.htm gives same error. 

I have only ArcGIS PRO 3.1 installed. 

0 Kudos
ShaunWalbridge
Esri Regular Contributor

Can you log a request through support? I'm not aware of what would cause this issue and don't know of any existing reports of it. Thanks!

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

I am experiencing the same problem .... in 3.0 i was able to run my python scripts without any errors, but after i upgraded to 3.1 and later I am getting only errors.  I run my scripts from within a .NET Module add-in (by calling a process to invoke propy.bat) or simply from a command line.  Neither works anymore.

I attached my Python script (change the extension back to .py).  It needs an input FileGeodatabase with a polygon feature class and a non-existing feature class for the output.  The script is doing buffer operation.  

So this what i get when i run the script using 3.0 (I only show the command line here):

"C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\propy.bat" "C:\Users\wolf2125\AppData\Local\ESRI\ArcGISPro\AssemblyCache\{31d7f807-1dfe-44c3-9c8b-6ffc8263159e}\test1.py" "C:\Data\FeatureTest\FeatureTest.gdb\TestPolygons" "C:\Data\FeatureTest\FeatureTest.gdb\TestPolygons_Buffer"

>> Output from Python (the output buffer polygon was created):
Input: C:\Data\FeatureTest\FeatureTest.gdb\TestPolygons
Output: C:\Data\FeatureTest\FeatureTest.gdb\TestPolygons_Buffer
Hello - this message is from a TEST Python script
Done

Next i uninstalled 3.0 and installed 3.1 and the same script can't be run.   I get this error from the command line:

"C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\propy.bat" "C:\Users\wolf2125\AppData\Local\ESRI\ArcGISPro\AssemblyCache\{31d7f807-1dfe-44c3-9c8b-6ffc8263159e}\test1.py" "C:\Data\FeatureTest\FeatureTest.gdb\TestPolygons" "C:\Data\FeatureTest\FeatureTest.gdb\TestPolygons_Buffer"
Input: C:\Data\FeatureTest\FeatureTest.gdb\TestPolygons
Output: C:\Data\FeatureTest\FeatureTest.gdb\TestPolygons_Buffer
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)

I can't run test1.py from my add-in either - since it's executing the exact same script.

It looks to me like arcpy is unable to find / load its underlying assemblies (ArcGIS.Core, Version=13.1.0.0).  I added the ArcGIS Pro bin to the Path environment, but that didn't help.

 

by Anonymous User
Not applicable

This is a mess... I started to notice that Pro 3.0 will sometimes load the Add-ins I created to execute python scripts.  I had to update to 3.1 as the 'solution' to test three other bugs I found and reported to esri... 3.1 just doesn't load a dockpane Addin I created at all, and I still have the 3 bugs.

Wolf
by Esri Regular Contributor
Esri Regular Contributor

@Anonymous User  i can probably help you with your add-in / dockpane issues.   I am working with the ArcGIS Pro SDK team.  I will probably need to see your code though ... you can send me a private message, or report your issues under 'ArcGIS Pro SDK Questions' ArcGIS Pro SDK Questions - Esri Community

Gerry_S
New Contributor

This is something I have experienced too after upgrading to Pro 3.1. However, and curiously, a small script I made that would fail elsewhere with this error did run inside the ArcGIS Pro python window. 

It does look like ArcGIS.Core is part of the ArcGIS Pro SDK (see Home · Esri/arcgis-pro-sdk Wiki (github.com)) so I tried uninstalling and reinstalling the ArcGIS Pro SDK in Visual Studio to see if it needed to be re-installed after a Pro update. No joy, still the same error.

Looking like I'll need to downgrade to Pro 3.0.x for now until there's a fix.